diff --git a/deploy/1-create-operator.yaml b/deploy/1-create-operator.yaml index 647290134..921388719 100644 --- a/deploy/1-create-operator.yaml +++ b/deploy/1-create-operator.yaml @@ -64,6 +64,7 @@ rules: - keystones - swifts - memcacheds + - contrailmonitorstatuses verbs: - '*' - apiGroups: @@ -740,6 +741,245 @@ spec: --- apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition +metadata: + name: contrailmonitorstatuses.contrail.juniper.net +spec: + group: contrail.juniper.net + names: + kind: ContrailMonitorStatus + listKind: ContrailMonitorStatusList + plural: contrailmonitorstatuses + singular: contrailmonitorstatus + scope: Namespaced + subresources: + status: {} + validation: + openAPIV3Schema: + description: ContrailMonitorStatus is the Schema for the contrailmonitorstatuses + API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: ContrailMonitorStatusSpec defines the desired state of ContrailMonitorStatus + properties: + commonConfiguration: + description: 'INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + Important: Run "operator-sdk generate k8s" to regenerate code after + modifying this file Add custom validation using kubebuilder tags: + https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html' + properties: + activate: + description: Activate defines if the service will be activated by + Manager. + type: boolean + create: + description: Create defines if the service will be created by Manager. + type: boolean + hostNetwork: + description: Host networking requested for this pod. Use the host's + network namespace. If this option is set, the ports that will + be used must be specified. Default to false. + type: boolean + imagePullSecrets: + description: ImagePullSecrets is an optional list of references + to secrets in the same namespace to use for pulling any of the + images used by this PodSpec. + items: + type: string + type: array + nodeSelector: + additionalProperties: + type: string + description: 'NodeSelector is a selector which must be true for + the pod to fit on a node. Selector which must match a node''s + labels for the pod to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/.' + type: object + replicas: + description: Number of desired pods. This is a pointer to distinguish + between explicit zero and not specified. Defaults to 1. + format: int32 + type: integer + tolerations: + description: If specified, the pod's tolerations. + items: + description: The pod this Toleration is attached to tolerates + any taint that matches the triple using the + matching operator . + properties: + effect: + description: Effect indicates the taint effect to match. Empty + means match all taint effects. When specified, allowed values + are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: Key is the taint key that the toleration applies + to. Empty means match all taint keys. If the key is empty, + operator must be Exists; this combination means to match + all values and all keys. + type: string + operator: + description: Operator represents a key's relationship to the + value. Valid operators are Exists and Equal. Defaults to + Equal. Exists is equivalent to wildcard for value, so that + a pod can tolerate all taints of a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the period of time + the toleration (which must be of effect NoExecute, otherwise + this field is ignored) tolerates the taint. By default, + it is not set, which means tolerate the taint forever (do + not evict). Zero and negative values will be treated as + 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration matches + to. If the operator is Exists, the value should be empty, + otherwise just a regular string. + type: string + type: object + type: array + type: object + serviceConfiguration: + description: ContrailMonitorStatusConfiguration is the Spec for the + ContrailMonitorStatus API. + properties: + cassandraInstance: + type: string + configInstance: + type: string + keystoneInstance: + type: string + memcachedInstance: + type: string + postgresInstance: + type: string + provisionmanagerInstance: + type: string + rabbitmqInstance: + type: string + zookeeperInstance: + type: string + type: object + required: + - commonConfiguration + - serviceConfiguration + type: object + status: + description: ContrailMonitorStatusStatus defines the observed state of ContrailMonitorStatus + properties: + active: + description: 'INSERT ADDITIONAL STATUS FIELD - define observed state + of cluster Important: Run "operator-sdk generate k8s" to regenerate + code after modifying this file Add custom validation using kubebuilder + tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html' + type: boolean + cassandras: + description: Controls []*ServiceStatus `json:"controls,omitempty"` + Kubemanagers []*ServiceStatus `json:"kubemanagers,omitempty"` + Webui *ServiceStatus `json:"webui,omitempty"` Vrouters []*ServiceStatus + `json:"vrouters,omitempty"` + items: + description: ServiceStatus provides information on the current status + of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + type: array + config: + description: ServiceStatus provides information on the current status + of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + keystone: + description: ProvisionManager *ServiceStatus `json:"provisionManager,omitempty"` + CrdStatus []CrdStatus `json:"crdStatus,omitempty"` + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + memcached: + description: Swift *ServiceStatus `json:"swift,omitempty"` + Command *ServiceStatus `json:"command,omitempty"` + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + postgres: + description: ServiceStatus provides information on the current status + of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + rabbitmq: + description: ServiceStatus provides information on the current status + of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + zookeepers: + items: + description: ServiceStatus provides information on the current status + of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + type: array + type: object + type: object + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition metadata: name: controls.contrail.juniper.net spec: @@ -926,6 +1166,19 @@ kind: CustomResourceDefinition metadata: name: keystones.contrail.juniper.net spec: + additionalPrinterColumns: + - JSONPath: .status.port + description: The number of ready Coherence Pods for this role + name: Port + type: integer + - JSONPath: .status.active + description: The number of ready Coherence Pods for this role + name: Active + type: boolean + - JSONPath: .status.ips + description: The number of ready Coherence Pods for this role + name: IPS + type: string group: contrail.juniper.net names: kind: Keystone @@ -1948,6 +2201,236 @@ spec: serviceStatus: {} type: object type: object + contrailmonitorstatus: + description: ContrailMonitorStatus is the Schema for the contrailmonitorstatuses + API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this + representation of an object. Servers should convert recognized + schemas to the latest internal value, and may reject unrecognized + values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource + this object represents. Servers may infer this from the endpoint + the client submits requests to. Cannot be updated. In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: ContrailMonitorStatusSpec defines the desired state + of ContrailMonitorStatus + properties: + commonConfiguration: + description: 'INSERT ADDITIONAL SPEC FIELDS - desired state + of cluster Important: Run "operator-sdk generate k8s" + to regenerate code after modifying this file Add custom + validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html' + properties: + activate: + description: Activate defines if the service will be + activated by Manager. + type: boolean + create: + description: Create defines if the service will be created + by Manager. + type: boolean + hostNetwork: + description: Host networking requested for this pod. + Use the host's network namespace. If this option is + set, the ports that will be used must be specified. + Default to false. + type: boolean + imagePullSecrets: + description: ImagePullSecrets is an optional list of + references to secrets in the same namespace to use + for pulling any of the images used by this PodSpec. + items: + type: string + type: array + nodeSelector: + additionalProperties: + type: string + description: 'NodeSelector is a selector which must + be true for the pod to fit on a node. Selector which + must match a node''s labels for the pod to be scheduled + on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/.' + type: object + replicas: + description: Number of desired pods. This is a pointer + to distinguish between explicit zero and not specified. + Defaults to 1. + format: int32 + type: integer + tolerations: + description: If specified, the pod's tolerations. + items: + description: The pod this Toleration is attached to + tolerates any taint that matches the triple + using the matching operator . + properties: + effect: + description: Effect indicates the taint effect + to match. Empty means match all taint effects. + When specified, allowed values are NoSchedule, + PreferNoSchedule and NoExecute. + type: string + key: + description: Key is the taint key that the toleration + applies to. Empty means match all taint keys. + If the key is empty, operator must be Exists; + this combination means to match all values and + all keys. + type: string + operator: + description: Operator represents a key's relationship + to the value. Valid operators are Exists and + Equal. Defaults to Equal. Exists is equivalent + to wildcard for value, so that a pod can tolerate + all taints of a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the + period of time the toleration (which must be + of effect NoExecute, otherwise this field is + ignored) tolerates the taint. By default, it + is not set, which means tolerate the taint forever + (do not evict). Zero and negative values will + be treated as 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration + matches to. If the operator is Exists, the value + should be empty, otherwise just a regular string. + type: string + type: object + type: array + type: object + serviceConfiguration: + description: ContrailMonitorStatusConfiguration is the Spec + for the ContrailMonitorStatus API. + properties: + cassandraInstance: + type: string + configInstance: + type: string + keystoneInstance: + type: string + memcachedInstance: + type: string + postgresInstance: + type: string + provisionmanagerInstance: + type: string + rabbitmqInstance: + type: string + zookeeperInstance: + type: string + type: object + required: + - commonConfiguration + - serviceConfiguration + type: object + status: + description: ContrailMonitorStatusStatus defines the observed + state of ContrailMonitorStatus + properties: + active: + description: 'INSERT ADDITIONAL STATUS FIELD - define observed + state of cluster Important: Run "operator-sdk generate + k8s" to regenerate code after modifying this file Add + custom validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html' + type: boolean + cassandras: + description: Controls []*ServiceStatus `json:"controls,omitempty"` + Kubemanagers []*ServiceStatus `json:"kubemanagers,omitempty"` + Webui *ServiceStatus `json:"webui,omitempty"` + Vrouters []*ServiceStatus `json:"vrouters,omitempty"` + items: + description: ServiceStatus provides information on the + current status of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + type: array + config: + description: ServiceStatus provides information on the current + status of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + keystone: + description: ProvisionManager *ServiceStatus `json:"provisionManager,omitempty"` + CrdStatus []CrdStatus `json:"crdStatus,omitempty"` + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + memcached: + description: Swift *ServiceStatus `json:"swift,omitempty"` + Command *ServiceStatus `json:"command,omitempty"` + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + postgres: + description: ServiceStatus provides information on the current + status of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + rabbitmq: + description: ServiceStatus provides information on the current + status of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + zookeepers: + items: + description: ServiceStatus provides information on the + current status of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object + type: array + type: object + type: object controls: items: description: Control is the Schema for the controls API. @@ -2094,8 +2577,6 @@ spec: type: string xmppPort: type: integer - zookeeperInstance: - type: string type: object required: - commonConfiguration @@ -3534,6 +4015,14 @@ spec: type: integer serverPort: type: integer + storage: + properties: + path: + type: string + size: + pattern: ^([0-9]+)([KMGTPE]i)?$ + type: string + type: object type: object required: - commonConfiguration @@ -3620,6 +4109,17 @@ spec: name: type: string type: object + contrailmonitorstatus: + description: ServiceStatus provides information on the current status + of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object controls: items: description: ServiceStatus provides information on the current status @@ -5083,6 +5583,14 @@ spec: type: integer serverPort: type: integer + storage: + properties: + path: + type: string + size: + pattern: ^([0-9]+)([KMGTPE]i)?$ + type: string + type: object type: object required: - commonConfiguration @@ -5140,7 +5648,7 @@ spec: containers: - name: contrail-operator # Replace this with the built image name - image: svl-artifactory.juniper.net/contrail-operator/engprod-269421/contrail-operator:master.latest + image: registry:5000/contrail-operator:latest imagePullPolicy: Always env: - name: WATCH_NAMESPACE diff --git a/deploy/crds/contrail.juniper.net_contrailmonitorstatuses_crd.yaml b/deploy/crds/contrail.juniper.net_contrailmonitorstatuses_crd.yaml new file mode 100644 index 000000000..63cee18ae --- /dev/null +++ b/deploy/crds/contrail.juniper.net_contrailmonitorstatuses_crd.yaml @@ -0,0 +1,160 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: contrailmonitorstatuses.contrail.juniper.net +spec: + group: contrail.juniper.net + names: + kind: ContrailMonitorStatus + listKind: ContrailMonitorStatusList + plural: contrailmonitorstatuses + singular: contrailmonitorstatus + scope: Namespaced + subresources: + status: {} + validation: + openAPIV3Schema: + description: ContrailMonitorStatus is the Schema for the contrailmonitorstatuses + API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: ContrailMonitorStatusSpec defines the desired state of ContrailMonitorStatus + properties: + commonConfiguration: + description: CommonConfiguration is the common services struct. + properties: + activate: + description: Activate defines if the service will be activated by + Manager. + type: boolean + create: + description: Create defines if the service will be created by Manager. + type: boolean + hostNetwork: + description: Host networking requested for this pod. Use the host's + network namespace. If this option is set, the ports that will + be used must be specified. Default to false. + type: boolean + imagePullSecrets: + description: ImagePullSecrets is an optional list of references + to secrets in the same namespace to use for pulling any of the + images used by this PodSpec. + items: + type: string + type: array + nodeSelector: + additionalProperties: + type: string + description: 'NodeSelector is a selector which must be true for + the pod to fit on a node. Selector which must match a node''s + labels for the pod to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/.' + type: object + replicas: + description: Number of desired pods. This is a pointer to distinguish + between explicit zero and not specified. Defaults to 1. + format: int32 + type: integer + tolerations: + description: If specified, the pod's tolerations. + items: + description: The pod this Toleration is attached to tolerates + any taint that matches the triple using the + matching operator . + properties: + effect: + description: Effect indicates the taint effect to match. Empty + means match all taint effects. When specified, allowed values + are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: Key is the taint key that the toleration applies + to. Empty means match all taint keys. If the key is empty, + operator must be Exists; this combination means to match + all values and all keys. + type: string + operator: + description: Operator represents a key's relationship to the + value. Valid operators are Exists and Equal. Defaults to + Equal. Exists is equivalent to wildcard for value, so that + a pod can tolerate all taints of a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the period of time + the toleration (which must be of effect NoExecute, otherwise + this field is ignored) tolerates the taint. By default, + it is not set, which means tolerate the taint forever (do + not evict). Zero and negative values will be treated as + 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration matches + to. If the operator is Exists, the value should be empty, + otherwise just a regular string. + type: string + type: object + type: array + type: object + serviceConfiguration: + description: ContrailMonitorStatusConfiguration is the Spec for the + ContrailMonitorStatus API. + properties: + cassandraInstance: + type: string + commandInstance: + type: string + configInstance: + type: string + controlInstance: + type: string + keystoneInstance: + type: string + memcachedInstance: + type: string + postgresInstance: + type: string + provisionmanagerInstance: + type: string + rabbitmqInstance: + type: string + zookeeperInstance: + type: string + type: object + required: + - commonConfiguration + - serviceConfiguration + type: object + status: + description: ContrailMonitorStatusStatus defines the observed state of ContrailMonitorStatus + properties: + config: + items: + description: ModuleStatus defines the observed state of ConfigStatus + properties: + moduleName: + type: string + state: + type: string + required: + - state + type: object + type: array + type: object + type: object + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true diff --git a/deploy/crds/contrail.juniper.net_managers_crd.yaml b/deploy/crds/contrail.juniper.net_managers_crd.yaml index 121e1f3d8..e10d5abe3 100644 --- a/deploy/crds/contrail.juniper.net_managers_crd.yaml +++ b/deploy/crds/contrail.juniper.net_managers_crd.yaml @@ -665,6 +665,160 @@ spec: serviceStatus: {} type: object type: object + contrailmonitorstatus: + description: ContrailMonitorStatus is the Schema for the contrailmonitorstatuses + API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this + representation of an object. Servers should convert recognized + schemas to the latest internal value, and may reject unrecognized + values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource + this object represents. Servers may infer this from the endpoint + the client submits requests to. Cannot be updated. In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: ContrailMonitorStatusSpec defines the desired state + of ContrailMonitorStatus + properties: + commonConfiguration: + description: CommonConfiguration is the common services + struct. + properties: + activate: + description: Activate defines if the service will be + activated by Manager. + type: boolean + create: + description: Create defines if the service will be created + by Manager. + type: boolean + hostNetwork: + description: Host networking requested for this pod. + Use the host's network namespace. If this option is + set, the ports that will be used must be specified. + Default to false. + type: boolean + imagePullSecrets: + description: ImagePullSecrets is an optional list of + references to secrets in the same namespace to use + for pulling any of the images used by this PodSpec. + items: + type: string + type: array + nodeSelector: + additionalProperties: + type: string + description: 'NodeSelector is a selector which must + be true for the pod to fit on a node. Selector which + must match a node''s labels for the pod to be scheduled + on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/.' + type: object + replicas: + description: Number of desired pods. This is a pointer + to distinguish between explicit zero and not specified. + Defaults to 1. + format: int32 + type: integer + tolerations: + description: If specified, the pod's tolerations. + items: + description: The pod this Toleration is attached to + tolerates any taint that matches the triple + using the matching operator . + properties: + effect: + description: Effect indicates the taint effect + to match. Empty means match all taint effects. + When specified, allowed values are NoSchedule, + PreferNoSchedule and NoExecute. + type: string + key: + description: Key is the taint key that the toleration + applies to. Empty means match all taint keys. + If the key is empty, operator must be Exists; + this combination means to match all values and + all keys. + type: string + operator: + description: Operator represents a key's relationship + to the value. Valid operators are Exists and + Equal. Defaults to Equal. Exists is equivalent + to wildcard for value, so that a pod can tolerate + all taints of a particular category. + type: string + tolerationSeconds: + description: TolerationSeconds represents the + period of time the toleration (which must be + of effect NoExecute, otherwise this field is + ignored) tolerates the taint. By default, it + is not set, which means tolerate the taint forever + (do not evict). Zero and negative values will + be treated as 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: Value is the taint value the toleration + matches to. If the operator is Exists, the value + should be empty, otherwise just a regular string. + type: string + type: object + type: array + type: object + serviceConfiguration: + description: ContrailMonitorStatusConfiguration is the Spec + for the ContrailMonitorStatus API. + properties: + cassandraInstance: + type: string + commandInstance: + type: string + configInstance: + type: string + controlInstance: + type: string + keystoneInstance: + type: string + memcachedInstance: + type: string + postgresInstance: + type: string + provisionmanagerInstance: + type: string + rabbitmqInstance: + type: string + zookeeperInstance: + type: string + type: object + required: + - commonConfiguration + - serviceConfiguration + type: object + status: + description: ContrailMonitorStatusStatus defines the observed + state of ContrailMonitorStatus + properties: + config: + items: + description: ModuleStatus defines the observed state of + ConfigStatus + properties: + moduleName: + type: string + state: + type: string + required: + - state + type: object + type: array + type: object + type: object controls: items: description: Control is the Schema for the controls API. @@ -2343,6 +2497,17 @@ spec: name: type: string type: object + contrailmonitorstatus: + description: ServiceStatus provides information on the current status + of the service. + properties: + active: + type: boolean + created: + type: boolean + name: + type: string + type: object controls: items: description: ServiceStatus provides information on the current status diff --git a/deploy/crds/contrail.juniper.net_v1alpha1_contrailmonitorstatus_cr.yaml b/deploy/crds/contrail.juniper.net_v1alpha1_contrailmonitorstatus_cr.yaml new file mode 100644 index 000000000..b0e958a0d --- /dev/null +++ b/deploy/crds/contrail.juniper.net_v1alpha1_contrailmonitorstatus_cr.yaml @@ -0,0 +1,7 @@ +apiVersion: contrail.juniper.net/v1alpha1 +kind: ContrailMonitorStatus +metadata: + name: example-contrailmonitorstatus +spec: + # Add fields here + size: 3 diff --git a/deploy/openshift/tools/contrail-sc-open/BUILD.bazel b/deploy/openshift/tools/contrail-sc-open/BUILD.bazel new file mode 100644 index 000000000..e2e2c193d --- /dev/null +++ b/deploy/openshift/tools/contrail-sc-open/BUILD.bazel @@ -0,0 +1,20 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "go_default_library", + srcs = ["main.go"], + importpath = "github.com/Juniper/contrail-operator/deploy/openshift/tools/contrail-sc-open", + visibility = ["//visibility:private"], + deps = [ + "@com_github_aws_aws_sdk_go//aws:go_default_library", + "@com_github_aws_aws_sdk_go//aws/awserr:go_default_library", + "@com_github_aws_aws_sdk_go//aws/session:go_default_library", + "@com_github_aws_aws_sdk_go//service/ec2:go_default_library", + ], +) + +go_binary( + name = "contrail-sc-open", + embed = [":go_default_library"], + visibility = ["//visibility:public"], +) diff --git a/pkg/apis/contrail/v1alpha1/contrailmonitorstatus_types.go b/pkg/apis/contrail/v1alpha1/contrailmonitorstatus_types.go new file mode 100644 index 000000000..bb90e97c1 --- /dev/null +++ b/pkg/apis/contrail/v1alpha1/contrailmonitorstatus_types.go @@ -0,0 +1,79 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// ContrailMonitorStatusSpec defines the desired state of ContrailMonitorStatus +type ContrailMonitorStatusSpec struct { + CommonConfiguration CommonConfiguration `json:"commonConfiguration"` + ServiceConfiguration ContrailMonitorStatusConfiguration `json:"serviceConfiguration"` +} + +// ContrailMonitorStatusConfiguration is the Spec for the ContrailMonitorStatus API. +// +k8s:openapi-gen=true +type ContrailMonitorStatusConfiguration struct { + MemcachedInstance string `json:"memcachedInstance,omitempty"` + PostgresInstance string `json:"postgresInstance,omitempty"` + CassandraInstance string `json:"cassandraInstance,omitempty"` + KeystoneInstance string `json:"keystoneInstance,omitempty"` + ConfigInstance string `json:"configInstance,omitempty"` + ZookeeperInstance string `json:"zookeeperInstance,omitempty"` + RabbitmqInstance string `json:"rabbitmqInstance,omitempty"` + ProvisionmanagerInstance string `json:"provisionmanagerInstance,omitempty"` + CommandInstance string `json:"commandInstance,omitempty"` + ControlInstance string `json:"controlInstance,omitempty"` +} + +// ContrailMonitorStatusStatus defines the observed state of ContrailMonitorStatus +type ContrailMonitorStatusStatus struct { + Active bool `json:"active,omitempty"` + + Config []*ModuleStatus `json:"config,omitempty"` + // Controls []*ServiceStatus `json:"controls,omitempty"` + // Kubemanagers []*ServiceStatus `json:"kubemanagers,omitempty"` + // Webui *ServiceStatus `json:"webui,omitempty"` + // Vrouters []*ServiceStatus `json:"vrouters,omitempty"` + // Cassandras []*ServiceStatus `json:"cassandras,omitempty"` + // Zookeepers []*ServiceStatus `json:"zookeepers,omitempty"` + // Rabbitmq *ServiceStatus `json:"rabbitmq,omitempty"` + // ProvisionManager *ServiceStatus `json:"provisionManager,omitempty"` + // CrdStatus []CrdStatus `json:"crdStatus,omitempty"` + // Keystone *ServiceStatus `json:"keystone,omitempty"` + // Postgres *ServiceStatus `json:"postgres,omitempty"` + // Swift *ServiceStatus `json:"swift,omitempty"` + // Command *ServiceStatus `json:"command,omitempty"` + // Memcached *ServiceStatus `json:"memcached,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ContrailMonitorStatus is the Schema for the contrailmonitorstatuses API +// +kubebuilder:subresource:status +// +kubebuilder:resource:path=contrailmonitorstatuses,scope=Namespaced +type ContrailMonitorStatus struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ContrailMonitorStatusSpec `json:"spec,omitempty"` + Status ContrailMonitorStatusStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// ContrailMonitorStatusList contains a list of ContrailMonitorStatus +type ContrailMonitorStatusList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ContrailMonitorStatus `json:"items"` +} + +func init() { + SchemeBuilder.Register(&ContrailMonitorStatus{}, &ContrailMonitorStatusList{}) +} + +// ModuleStatus defines the observed state of ConfigStatus +// +k8s:openapi-gen=true +type ModuleStatus struct { + ModuleName string `json:"moduleName,omitempty"` + ModuleState string `json:"state"` +} diff --git a/pkg/apis/contrail/v1alpha1/manager_types.go b/pkg/apis/contrail/v1alpha1/manager_types.go index 12e47fa82..ba38e0c7c 100644 --- a/pkg/apis/contrail/v1alpha1/manager_types.go +++ b/pkg/apis/contrail/v1alpha1/manager_types.go @@ -23,20 +23,21 @@ type ManagerSpec struct { // Services defines the desired state of Services. // +k8s:openapi-gen=true type Services struct { - Config *Config `json:"config,omitempty"` - Controls []*Control `json:"controls,omitempty"` - Kubemanagers []*Kubemanager `json:"kubemanagers,omitempty"` - Webui *Webui `json:"webui,omitempty"` - Vrouters []*Vrouter `json:"vrouters,omitempty"` - Cassandras []*Cassandra `json:"cassandras,omitempty"` - Zookeepers []*Zookeeper `json:"zookeepers,omitempty"` - Rabbitmq *Rabbitmq `json:"rabbitmq,omitempty"` - ProvisionManager *ProvisionManager `json:"provisionManager,omitempty"` - Command *Command `json:"command,omitempty"` - Postgres *Postgres `json:"postgres,omitempty"` - Keystone *Keystone `json:"keystone,omitempty"` - Swift *Swift `json:"swift,omitempty"` - Memcached *Memcached `json:"memcached,omitempty"` + Config *Config `json:"config,omitempty"` + Controls []*Control `json:"controls,omitempty"` + Kubemanagers []*Kubemanager `json:"kubemanagers,omitempty"` + Webui *Webui `json:"webui,omitempty"` + Vrouters []*Vrouter `json:"vrouters,omitempty"` + Cassandras []*Cassandra `json:"cassandras,omitempty"` + Zookeepers []*Zookeeper `json:"zookeepers,omitempty"` + Rabbitmq *Rabbitmq `json:"rabbitmq,omitempty"` + ProvisionManager *ProvisionManager `json:"provisionManager,omitempty"` + Command *Command `json:"command,omitempty"` + Postgres *Postgres `json:"postgres,omitempty"` + Keystone *Keystone `json:"keystone,omitempty"` + Swift *Swift `json:"swift,omitempty"` + Memcached *Memcached `json:"memcached,omitempty"` + ContrailMonitorStatus *ContrailMonitorStatus `json:"contrailmonitorstatus,omitempty"` } // ManagerStatus defines the observed state of Manager. @@ -45,21 +46,22 @@ type ManagerStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html - Config *ServiceStatus `json:"config,omitempty"` - Controls []*ServiceStatus `json:"controls,omitempty"` - Kubemanagers []*ServiceStatus `json:"kubemanagers,omitempty"` - Webui *ServiceStatus `json:"webui,omitempty"` - Vrouters []*ServiceStatus `json:"vrouters,omitempty"` - Cassandras []*ServiceStatus `json:"cassandras,omitempty"` - Zookeepers []*ServiceStatus `json:"zookeepers,omitempty"` - Rabbitmq *ServiceStatus `json:"rabbitmq,omitempty"` - ProvisionManager *ServiceStatus `json:"provisionManager,omitempty"` - CrdStatus []CrdStatus `json:"crdStatus,omitempty"` - Keystone *ServiceStatus `json:"keystone,omitempty"` - Postgres *ServiceStatus `json:"postgres,omitempty"` - Swift *ServiceStatus `json:"swift,omitempty"` - Command *ServiceStatus `json:"command,omitempty"` - Memcached *ServiceStatus `json:"memcached,omitempty"` + Config *ServiceStatus `json:"config,omitempty"` + Controls []*ServiceStatus `json:"controls,omitempty"` + Kubemanagers []*ServiceStatus `json:"kubemanagers,omitempty"` + Webui *ServiceStatus `json:"webui,omitempty"` + Vrouters []*ServiceStatus `json:"vrouters,omitempty"` + Cassandras []*ServiceStatus `json:"cassandras,omitempty"` + Zookeepers []*ServiceStatus `json:"zookeepers,omitempty"` + Rabbitmq *ServiceStatus `json:"rabbitmq,omitempty"` + ProvisionManager *ServiceStatus `json:"provisionManager,omitempty"` + CrdStatus []CrdStatus `json:"crdStatus,omitempty"` + Keystone *ServiceStatus `json:"keystone,omitempty"` + Postgres *ServiceStatus `json:"postgres,omitempty"` + Swift *ServiceStatus `json:"swift,omitempty"` + Command *ServiceStatus `json:"command,omitempty"` + Memcached *ServiceStatus `json:"memcached,omitempty"` + ContrailMonitorStatus *ServiceStatus `json:"contrailmonitorstatus,omitempty"` // +optional // +patchMergeKey=type // +patchStrategy=merge @@ -209,6 +211,9 @@ func (m Manager) IsClusterReady() bool { if m.Spec.Services.Memcached != nil && !m.Status.Memcached.ready() { return false } + if m.Spec.Services.ContrailMonitorStatus != nil && !m.Status.ContrailMonitorStatus.ready() { + return false + } return true } diff --git a/pkg/apis/contrail/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/contrail/v1alpha1/zz_generated.deepcopy.go index a74250d79..73bfc4225 100644 --- a/pkg/apis/contrail/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/contrail/v1alpha1/zz_generated.deepcopy.go @@ -836,6 +836,128 @@ func (in *Container) DeepCopy() *Container { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContrailMonitorStatus) DeepCopyInto(out *ContrailMonitorStatus) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailMonitorStatus. +func (in *ContrailMonitorStatus) DeepCopy() *ContrailMonitorStatus { + if in == nil { + return nil + } + out := new(ContrailMonitorStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ContrailMonitorStatus) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContrailMonitorStatusConfiguration) DeepCopyInto(out *ContrailMonitorStatusConfiguration) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailMonitorStatusConfiguration. +func (in *ContrailMonitorStatusConfiguration) DeepCopy() *ContrailMonitorStatusConfiguration { + if in == nil { + return nil + } + out := new(ContrailMonitorStatusConfiguration) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContrailMonitorStatusList) DeepCopyInto(out *ContrailMonitorStatusList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ContrailMonitorStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailMonitorStatusList. +func (in *ContrailMonitorStatusList) DeepCopy() *ContrailMonitorStatusList { + if in == nil { + return nil + } + out := new(ContrailMonitorStatusList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ContrailMonitorStatusList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContrailMonitorStatusSpec) DeepCopyInto(out *ContrailMonitorStatusSpec) { + *out = *in + in.CommonConfiguration.DeepCopyInto(&out.CommonConfiguration) + out.ServiceConfiguration = in.ServiceConfiguration + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailMonitorStatusSpec. +func (in *ContrailMonitorStatusSpec) DeepCopy() *ContrailMonitorStatusSpec { + if in == nil { + return nil + } + out := new(ContrailMonitorStatusSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContrailMonitorStatusStatus) DeepCopyInto(out *ContrailMonitorStatusStatus) { + *out = *in + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = make([]*ModuleStatus, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(ModuleStatus) + **out = **in + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailMonitorStatusStatus. +func (in *ContrailMonitorStatusStatus) DeepCopy() *ContrailMonitorStatusStatus { + if in == nil { + return nil + } + out := new(ContrailMonitorStatusStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Control) DeepCopyInto(out *Control) { *out = *in @@ -1686,6 +1808,11 @@ func (in *ManagerStatus) DeepCopyInto(out *ManagerStatus) { *out = new(ServiceStatus) (*in).DeepCopyInto(*out) } + if in.ContrailMonitorStatus != nil { + in, out := &in.ContrailMonitorStatus, &out.ContrailMonitorStatus + *out = new(ServiceStatus) + (*in).DeepCopyInto(*out) + } if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions *out = make([]ManagerCondition, len(*in)) @@ -1825,6 +1952,22 @@ func (in *MemcachedStatus) DeepCopy() *MemcachedStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ModuleStatus) DeepCopyInto(out *ModuleStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ModuleStatus. +func (in *ModuleStatus) DeepCopy() *ModuleStatus { + if in == nil { + return nil + } + out := new(ModuleStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MonitorConfig) DeepCopyInto(out *MonitorConfig) { *out = *in @@ -2446,6 +2589,11 @@ func (in *Services) DeepCopyInto(out *Services) { *out = new(Memcached) (*in).DeepCopyInto(*out) } + if in.ContrailMonitorStatus != nil { + in, out := &in.ContrailMonitorStatus, &out.ContrailMonitorStatus + *out = new(ContrailMonitorStatus) + (*in).DeepCopyInto(*out) + } return } diff --git a/pkg/controller/add_contrailmonitorstatus.go b/pkg/controller/add_contrailmonitorstatus.go new file mode 100644 index 000000000..8658e7959 --- /dev/null +++ b/pkg/controller/add_contrailmonitorstatus.go @@ -0,0 +1,10 @@ +package controller + +import ( + "github.com/Juniper/contrail-operator/pkg/controller/contrailmonitorstatus" +) + +func init() { + // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. + AddToManagerFuncs = append(AddToManagerFuncs, contrailmonitorstatus.Add) +} diff --git a/pkg/controller/contrailmonitorstatus/BUILD.bazel b/pkg/controller/contrailmonitorstatus/BUILD.bazel new file mode 100644 index 000000000..fb34cc6c1 --- /dev/null +++ b/pkg/controller/contrailmonitorstatus/BUILD.bazel @@ -0,0 +1,24 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["contrailmonitorstatus_controller.go"], + importpath = "github.com/Juniper/contrail-operator/pkg/controller/contrailmonitorstatus", + visibility = ["//visibility:public"], + deps = [ + "//pkg/apis/contrail/v1alpha1:go_default_library", + "@io_k8s_api//core/v1:go_default_library", + "@io_k8s_apimachinery//pkg/api/errors:go_default_library", + "@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library", + "@io_k8s_apimachinery//pkg/runtime:go_default_library", + "@io_k8s_apimachinery//pkg/types:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/client:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/controller:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/controller/controllerutil:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/handler:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/log:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/manager:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/reconcile:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/source:go_default_library", + ], +) diff --git a/pkg/controller/contrailmonitorstatus/config.yaml b/pkg/controller/contrailmonitorstatus/config.yaml new file mode 100644 index 000000000..67b0ccd30 --- /dev/null +++ b/pkg/controller/contrailmonitorstatus/config.yaml @@ -0,0 +1,19 @@ +apiServerList: + - localhost:8096::contrail-device-manager + - localhost:8088::contrail-svc-monitor + - localhost:8090::contrail-analytics-api + - localhost:8089::contrail-collector + - localhost:8084::contrail-api + - localhost:8087::contrail-schema +encryption: + ca: /Users/vraparla/go-workspace/src/projects/contrail-operator-dev-certs/ca-bundle.crt + cert: /Users/vraparla/go-workspace/src/projects/contrail-operator-dev-certs/server-172.17.0.3.crt + key: /Users/vraparla/go-workspace/src/projects/contrail-operator-dev-certs/server-key-172.17.0.3.pem + insecure: true +nodeType: config +interval: 5 +hostname: kind-control-plane +inCluster: false +nodeName: config1 +namespace: contrail +podName: config1-config-statefulset-0 diff --git a/pkg/controller/contrailmonitorstatus/contrailmonitorstatus_controller.go b/pkg/controller/contrailmonitorstatus/contrailmonitorstatus_controller.go new file mode 100644 index 000000000..1b2f83e76 --- /dev/null +++ b/pkg/controller/contrailmonitorstatus/contrailmonitorstatus_controller.go @@ -0,0 +1,837 @@ +package contrailmonitorstatus + +import ( + "context" + "fmt" + // "encoding/json" + apps "k8s.io/api/apps/v1" + + "github.com/Juniper/contrail-operator/pkg/apis/contrail/v1alpha1" + contrailv1alpha1 "github.com/Juniper/contrail-operator/pkg/apis/contrail/v1alpha1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/handler" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/source" + + + "github.com/Juniper/contrail-operator/pkg/k8s" + // "sigs.k8s.io/controller-runtime/pkg/cache" + + // "sigs.k8s.io/controller-runtime/pkg/event" + // "k8s.io/client-go/util/workqueue" + // "github.com/Juniper/contrail-operator/pkg/controller/utils" + // ty "github.com/Juniper/contrail-operator/statusmonitor" + // "k8s.io/client-go/kubernetes" + // "k8s.io/client-go/kubernetes/scheme" + // "k8s.io/client-go/rest" + // "k8s.io/client-go/tools/clientcmd" + + "k8s.io/apimachinery/pkg/labels" + + +) + +var log = logf.Log.WithName("controller_contrailmonitorstatus") + +/** +* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller +* business logic. Delete these comments after modifying this file.* + */ +// var log = logf.Log.WithName("controller_control") + +// func resourceHandler(myclient client.Client) handler.Funcs { +// appHandler := handler.Funcs{ +// CreateFunc: func(e event.CreateEvent, q workqueue.RateLimitingInterface) { +// listOps := &client.ListOptions{Namespace: e.Meta.GetNamespace()} +// list := &v1alpha1.ContrailMonitorStatusList{} +// err := myclient.List(context.TODO(), list, listOps) +// if err == nil { +// for _, app := range list.Items { +// q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ +// Name: app.GetName(), +// Namespace: e.Meta.GetNamespace(), +// }}) +// } +// } +// }, +// UpdateFunc: func(e event.UpdateEvent, q workqueue.RateLimitingInterface) { +// listOps := &client.ListOptions{Namespace: e.MetaNew.GetNamespace()} +// list := &v1alpha1.ContrailMonitorStatusList{} +// err := myclient.List(context.TODO(), list, listOps) +// if err == nil { +// for _, app := range list.Items { +// q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ +// Name: app.GetName(), +// Namespace: e.MetaNew.GetNamespace(), +// }}) +// } +// } +// }, +// DeleteFunc: func(e event.DeleteEvent, q workqueue.RateLimitingInterface) { +// listOps := &client.ListOptions{Namespace: e.Meta.GetNamespace()} +// list := &v1alpha1.ContrailMonitorStatusList{} +// err := myclient.List(context.TODO(), list, listOps) +// if err == nil { +// for _, app := range list.Items { +// q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ +// Name: app.GetName(), +// Namespace: e.Meta.GetNamespace(), +// }}) +// } +// } +// }, +// GenericFunc: func(e event.GenericEvent, q workqueue.RateLimitingInterface) { +// listOps := &client.ListOptions{Namespace: e.Meta.GetNamespace()} +// list := &v1alpha1.ContrailMonitorStatusList{} +// err := myclient.List(context.TODO(), list, listOps) +// if err == nil { +// for _, app := range list.Items { +// q.Add(reconcile.Request{NamespacedName: types.NamespacedName{ +// Name: app.GetName(), +// Namespace: e.Meta.GetNamespace(), +// }}) +// } +// } +// }, +// } +// return appHandler +// } + +// Add creates a new ContrailMonitorStatus Controller and adds it to the Manager. The Manager will set fields on the Controller +// and Start it when the Manager is Started. +func Add(mgr manager.Manager) error { + return add(mgr, newReconciler(mgr)) +} + +// newReconciler returns a new reconcile.Reconciler +func newReconciler(mgr manager.Manager) reconcile.Reconciler { + return &ReconcileContrailMonitorStatus{client: mgr.GetClient(), + scheme: mgr.GetScheme(), + manager: mgr, + kubernetes: k8s.New(mgr.GetClient(), mgr.GetScheme())} +} + +// add adds a new Controller to mgr with r as the reconcile.Reconciler +func add(mgr manager.Manager, r reconcile.Reconciler) error { + // Create a new controller + c, err := controller.New("contrailmonitorstatus-controller", mgr, controller.Options{Reconciler: r}) + if err != nil { + return err + } + + // Watch for changes to primary resource ContrailMonitorStatus + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.ContrailMonitorStatus{}}, &handler.EnqueueRequestForObject{}) + if err != nil { + return err + } + + /* + srcManager := &source.Kind{Type: &v1alpha1.Manager{}} + managerHandler := resourceHandler(mgr.GetClient()) + if err = c.Watch(srcManager, managerHandler); err != nil { + return err + } + srcConfig := &source.Kind{Type: &v1alpha1.Config{}} + configHandler := resourceHandler(mgr.GetClient()) + predConfigActiveChange := utils.ConfigActiveChange() + if err = c.Watch(srcConfig, configHandler, predConfigActiveChange); err != nil { + return err + } + srcControl := &source.Kind{Type: &v1alpha1.Control{}} + controlHandler := resourceHandler(mgr.GetClient()) + predControlActiveChange := utils.ControlActiveChange() + if err = c.Watch(srcControl, controlHandler, predControlActiveChange); err != nil { + return err + } + srcVrouter := &source.Kind{Type: &v1alpha1.Vrouter{}} + vrouterHandler := resourceHandler(mgr.GetClient()) + predVrouterActiveChange := utils.VrouterActiveChange() + if err = c.Watch(srcVrouter, vrouterHandler, predVrouterActiveChange); err != nil { + return err + } + srcRabbitmq := &source.Kind{Type: &v1alpha1.Rabbitmq{}} + rabbitmqHandler := resourceHandler(mgr.GetClient()) + predRabbitmqSizeChange := utils.RabbitmqActiveChange() + if err = c.Watch(srcRabbitmq, rabbitmqHandler, predRabbitmqSizeChange); err != nil { + return err + } + srcZookeeper := &source.Kind{Type: &v1alpha1.Zookeeper{}} + zookeeperHandler := resourceHandler(mgr.GetClient()) + predxookeeperSizeChange := utils.ZookeeperActiveChange() + if err = c.Watch(srcZookeeper, zookeeperHandler, predxookeeperSizeChange); err != nil { + return err + } + */ + + // TODO(user): Modify this to be the types you create that are owned by the primary resource + // Watch for changes to secondary resource Pods and requeue the owner ContrailMonitorStatus + err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &contrailv1alpha1.ContrailMonitorStatus{}, + }) + if err != nil { + return err + } + // Watch for changes to secondary resource Postgres and requeue the owner Keystone + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Postgres{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.ContrailMonitorStatus{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Memcached{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.ContrailMonitorStatus{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Cassandra{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.ContrailMonitorStatus{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Control{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.ContrailMonitorStatus{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Config{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.ContrailMonitorStatus{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Keystone{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.ContrailMonitorStatus{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Zookeeper{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.ContrailMonitorStatus{}, + }) + if err != nil { + return err + } + return nil +} + +// blank assignment to verify that ReconcileContrailMonitorStatus implements reconcile.Reconciler +var _ reconcile.Reconciler = &ReconcileContrailMonitorStatus{} + +// ReconcileContrailMonitorStatus reconciles a ContrailMonitorStatus object +type ReconcileContrailMonitorStatus struct { + // This client, initialized using mgr.Client() above, is a split client + // that reads objects from the cache and writes to the apiserver + client client.Client + scheme *runtime.Scheme + manager manager.Manager + kubernetes *k8s.Kubernetes +} + +// Reconcile reconciles ContrailMonitorStatus resource +func (r *ReconcileContrailMonitorStatus) Reconcile(request reconcile.Request) (reconcile.Result, error) { + reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) + reqLogger.Info("Reconciling ContrailMonitorStatus") + + // Fetch the ContrailMonitorStatus instance + instance := &contrailv1alpha1.ContrailMonitorStatus{} + err := r.client.Get(context.TODO(), request.NamespacedName, instance) + + if err != nil { + if errors.IsNotFound(err) { + return reconcile.Result{}, nil + } + return reconcile.Result{}, err + } + // uodate customer + err = r.client.Update(context.TODO(), instance) + if err != nil { + return reconcile.Result{}, err + } + if !instance.GetDeletionTimestamp().IsZero() { + return reconcile.Result{}, nil + } + + /* + cassandraInstance := v1alpha1.Cassandra{} + rabbitmqInstance := v1alpha1.Rabbitmq{} + configInstance := v1alpha1.Config{} + zookeeperInstance := v1alpha1.Zookeeper{} + provisionmanagerInstance := v1alpha1.ProvisionManager{} + cassandraActive := cassandraInstance.IsActive(instance.Spec.ServiceConfiguration.CassandraInstance, + request.Namespace, r.client) + rabbitmqActive := rabbitmqInstance.IsActive(instance.Labels["contrail_cluster"], + request.Namespace, r.client) + configActive := configInstance.IsActive(instance.Labels["contrail_cluster"], + request.Namespace, r.client) + zookeeperActive := zookeeperInstance.IsActive(instance.Labels["contrail_cluster"], + request.Namespace, r.client) + + if !configActive || !cassandraActive || !rabbitmqActive || !zookeeperActive { + return reconcile.Result{}, nil + } + testingPods, err := r.listReconcilePods(instance.Name) + if err != nil { + return reconcile.Result{}, fmt.Errorf("failed to list pods: %v", err) + } + err = yaml.Unmarshal(configYaml, &config) + if err != nil { + panic(err) + } + */ + + + ///////////////////////////////////////////// + + psql, err := r.getPostgres(instance) + if err != nil { + return reconcile.Result{}, err + } + + if err = r.kubernetes.Owner(instance).EnsureOwns(psql); err != nil { + return reconcile.Result{}, err + } + if !psql.Status.Active { + return reconcile.Result{}, nil + } + memcached, err := r.getMemcached(instance) + if err != nil { + return reconcile.Result{}, err + } + if err = r.kubernetes.Owner(instance).EnsureOwns(memcached); err != nil { + return reconcile.Result{}, err + } + if !memcached.Status.Active { + return reconcile.Result{}, nil + } + cassandra, err := r.getCassandra(instance) + if err != nil { + return reconcile.Result{}, err + } + if err = r.kubernetes.Owner(instance).EnsureOwns(cassandra); err != nil { + return reconcile.Result{}, err + } + if !*cassandra.Status.Active { + return reconcile.Result{}, nil + } + // keystone, err := r.getKeystone(instance) + // if err != nil { + // return reconcile.Result{}, err + // } + // if err = r.kubernetes.Owner(instance).EnsureOwns(keystone); err != nil { + // return reconcile.Result{}, err + // } + // if !keystone.Status.Active { + // return reconcile.Result{}, nil + // } + zookeeper, err := r.getZookeeper(instance) + if err != nil { + return reconcile.Result{}, err + } + if err = r.kubernetes.Owner(instance).EnsureOwns(zookeeper); err != nil { + return reconcile.Result{}, err + } + if !*zookeeper.Status.Active { + return reconcile.Result{}, nil + } + rabbitmq, err := r.getRabbitmq(instance) + if err != nil { + return reconcile.Result{}, err + } + if err = r.kubernetes.Owner(instance).EnsureOwns(rabbitmq); err != nil { + return reconcile.Result{}, err + } + if !*rabbitmq.Status.Active { + return reconcile.Result{}, nil + } + config, err := r.getConfig(instance) + if err != nil { + return reconcile.Result{}, err + } + // if err = r.kubernetes.Owner(instance).EnsureOwns(config); err != nil { + // return reconcile.Result{}, err + // } + // if !*config.Status.Active { + // return reconcile.Result{}, nil + // } + fmt.Println("++++++++++++++++++++++") + fmt.Println("++++++++++++++++++++++") + fmt.Println("*******************8***") + fmt.Println("^^^^^^^^^^8***") + for i := 0; i < len(config.Items); i++{ + fmt.Println(*config.Items[i].Status.Active) + for _, value := range config.Items[i].Status.ServiceStatus{ + for m, n := range value { + fmt.Println(m, "::", n.ModuleName, "::", n.ModuleState) + } + } + } + + // r.client.Create(context.Background(), ABC, ) + + fmt.Println("*******************8***") + fmt.Println("++++++++++++++++++++++") + /* + control, err := r.getControl(instance) + if err != nil { + return reconcile.Result{}, err + } + if err = r.kubernetes.Owner(instance).EnsureOwns(control); err != nil { + return reconcile.Result{}, err + } + if !*control.Status.Active { + return reconcile.Result{}, nil + } + command, err := r.getCommand(instance) + if err != nil { + return reconcile.Result{}, err + } + if err = r.kubernetes.Owner(instance).EnsureOwns(command); err != nil { + return reconcile.Result{}, err + } + if !command.Status.Active { + return reconcile.Result{}, nil + } + fmt.Println(command.Name, command.Namespace) + provisionmanager, err := r.getProvisionmanager(instance) + if err != nil { + return reconcile.Result{}, err + } + if err = r.kubernetes.Owner(instance).EnsureOwns(provisionmanager); err != nil { + return reconcile.Result{}, err + } + if !*provisionmanager.Status.Active { + return reconcile.Result{}, nil + } +*/ + fmt.Println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&") + fmt.Println("****************************") + fmt.Println("****************************") + fmt.Println(memcached.Name, memcached.Namespace, memcached.Status.Active) + fmt.Println(psql.Name, psql.Namespace, psql.Status.Active) + fmt.Println(cassandra.Name, cassandra.Namespace, *cassandra.Status.Active) + // fmt.Println(rabbitmq.Name, rabbitmq.Namespace, *rabbitmq.Status.Active) + // fmt.Println(zookeeper.Name, zookeeper.Namespace, *zookeeper.Status.Active) + // fmt.Println(keystone.Name, keystone.Namespace, keystone.Status.Active) + // fmt.Println(config.Name, config.Namespace) + // fmt.Println(control.Name, control.Namespace) + // fmt.Println(provisionmanager.Name, provisionmanager.Namespace) + // fmt.Println(command.Name, provisionmanager.Namespace) + fmt.Println("****************************") + fmt.Println("****************************") + fmt.Println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&") + + ///////////////////////////////////////////// + + // Define a new Pod object + pod := newPodForCR(instance) + + // Set ContrailMonitorStatus instance as the owner and controller + if err := controllerutil.SetControllerReference(instance, pod, r.scheme); err != nil { + return reconcile.Result{}, err + } + + // Check if this Pod already exists + found := &corev1.Pod{} + err = r.client.Get(context.TODO(), types.NamespacedName{Name: pod.Name, Namespace: pod.Namespace}, found) + if err != nil && errors.IsNotFound(err) { + reqLogger.Info("Creating a new Pod", "Pod.Namespace", pod.Namespace, "Pod.Name", pod.Name) + err = r.client.Create(context.TODO(), pod) + if err != nil { + return reconcile.Result{}, err + } + + // Pod created successfully - don't requeue + return reconcile.Result{}, nil + } else if err != nil { + return reconcile.Result{}, err + } + + // Pod already exists - don't requeue + reqLogger.Info("Skip reconcile: Pod already exists", "Pod.Namespace", found.Namespace, "Pod.Name", found.Name) + + deployment := &apps.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: request.Namespace, + Name: request.Name + "-deployment", + }, + } + _, err = controllerutil.CreateOrUpdate(context.Background(), r.client, deployment, func() error { + labels := map[string]string{"contrailmonitorstatus": request.Name} + deployment.Spec.Template.ObjectMeta.Labels = labels + deployment.ObjectMeta.Labels = labels + deployment.Spec.Selector = &metav1.LabelSelector{MatchLabels: labels} + // updateMemcachedPodSpec(&deployment.Spec.Template.Spec, memcachedCR, memcachedConfigMapName) + return controllerutil.SetControllerReference(instance, deployment, r.scheme) + }) + if err != nil { + return reconcile.Result{}, err + } + return reconcile.Result{}, r.updateStatus(instance, deployment) + + // return reconcile.Result{}, nil +} + +func (r *ReconcileContrailMonitorStatus) getControl(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Control, error) { + // listOps := &client.ListOptions{Namespace: "contrail"} + // ctrllist := &v1alpha1.ControlList{} + // err := r.client.List(context.TODO(), ctrllist, listOps) + ctrlIns := &contrailv1alpha1.Control{} + err := r.client.Get(context.TODO(), + types.NamespacedName{ + Namespace: cr.Namespace, + Name: cr.Spec.ServiceConfiguration.ControlInstance, + }, ctrlIns) + + return ctrlIns, err +} + + +func (r *ReconcileContrailMonitorStatus) getPostgres(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Postgres, error) { + // listOps := &client.ListOptions{Namespace: "contrail"} + // plist := &v1alpha1.PostgresList{} + // err := r.client.List(context.TODO(), plist, listOps) + psql := &contrailv1alpha1.Postgres{} + err := r.client.Get(context.TODO(), + types.NamespacedName{ + Namespace: cr.Namespace, + Name: cr.Spec.ServiceConfiguration.PostgresInstance, + }, psql) + + return psql, err +} + +func (r *ReconcileContrailMonitorStatus) getMemcached(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Memcached, error) { + + // listOps := &client.ListOptions{Namespace: "contrail"} + // mlist := &v1alpha1.MemcachedList{} + // err := r.client.List(context.TODO(), mlist, listOps) + key := &contrailv1alpha1.Memcached{} + name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.MemcachedInstance} + err := r.client.Get(context.Background(), name, key) + return key, err +} + +func (r *ReconcileContrailMonitorStatus) getCassandra(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Cassandra, error) { + + // listOps := &client.ListOptions{Namespace: "contrail"} + // mlist := &v1alpha1.MemcachedList{} + // err := r.client.List(context.TODO(), mlist, listOps) + key := &contrailv1alpha1.Cassandra{} + name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.CassandraInstance} + err := r.client.Get(context.Background(), name, key) + return key, err +} + +func (r *ReconcileContrailMonitorStatus) getProvisionmanager(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.ProvisionManager, error) { + + // listOps := &client.ListOptions{Namespace: "contrail"} + // mlist := &v1alpha1.MemcachedList{} + // err := r.client.List(context.TODO(), mlist, listOps) + key := &contrailv1alpha1.ProvisionManager{} + name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.ProvisionmanagerInstance} + err := r.client.Get(context.Background(), name, key) + return key, err +} + +func (r *ReconcileContrailMonitorStatus) getZookeeper(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Zookeeper, error) { + + // listOps := &client.ListOptions{Namespace: "contrail"} + // mlist := &v1alpha1.MemcachedList{} + // err := r.client.List(context.TODO(), mlist, listOps) + key := &contrailv1alpha1.Zookeeper{} + name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.ZookeeperInstance} + err := r.client.Get(context.Background(), name, key) + return key, err +} + +func (r *ReconcileContrailMonitorStatus) getRabbitmq(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Rabbitmq, error) { + + // listOps := &client.ListOptions{Namespace: "contrail"} + // mlist := &v1alpha1.MemcachedList{} + // err := r.client.List(context.TODO(), mlist, listOps) + key := &contrailv1alpha1.Rabbitmq{} + name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.RabbitmqInstance} + err := r.client.Get(context.Background(), name, key) + return key, err +} + +// func (r *ReconcileContrailMonitorStatus) getConfig(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Config, error) { +func (r *ReconcileContrailMonitorStatus) getConfig(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.ConfigList, error) { + listOps := &client.ListOptions{Namespace: "contrail"} + mlist := &v1alpha1.ConfigList{} + err := r.client.List(context.TODO(), mlist, listOps) + // key := &contrailv1alpha1.Config{} + // name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.ConfigInstance} + // err := r.client.Get(context.Background(), name, key) + // return key, err + return mlist, err +} + +func (r *ReconcileContrailMonitorStatus) getKeystone(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Keystone, error) { + + // listOps := &client.ListOptions{Namespace: "contrail"} + // mlist := &v1alpha1.KeystoneList{} + // err := r.client.List(context.TODO(), mlist, listOps) + key := &contrailv1alpha1.Keystone{} + name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.KeystoneInstance} + err := r.client.Get(context.Background(), name, key) + return key, err +} + +func (r *ReconcileContrailMonitorStatus) getCommand(cr *contrailv1alpha1.ContrailMonitorStatus) (*contrailv1alpha1.Command, error) { + + // listOps := &client.ListOptions{Namespace: "contrail"} + // mlist := &v1alpha1.CommandList{} + // err := r.client.List(context.TODO(), mlist, listOps) + key := &contrailv1alpha1.Command{} + name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.CommandInstance} + err := r.client.Get(context.Background(), name, key) + return key, err +} + + +func (r *ReconcileContrailMonitorStatus) updateStatus(memcachedCR *contrailv1alpha1.ContrailMonitorStatus, deployment *apps.Deployment) error { + err := r.client.Get(context.Background(), types.NamespacedName{Name: deployment.Name, Namespace: deployment.Namespace}, deployment) + if err != nil { + return err + } + // expectedReplicas := int32(1) + // if deployment.Spec.Replicas != nil { + // expectedReplicas = *deployment.Spec.Replicas + // } + // if deployment.Status.ReadyReplicas == expectedReplicas { + // pods := core.PodList{} + // var labels client.MatchingLabels = deployment.Spec.Selector.MatchLabels + // if err = r.client.List(context.Background(), &pods, labels); err != nil { + // return err + // } + // if len(pods.Items) != 1 { + // return fmt.Errorf("ReconcileMemchached.updateStatus: expected 1 pod with labels %v, got %d", labels, len(pods.Items)) + // } + // ip := "127.0.0.1" // memcached is available only on localhost for security reasons, after configuring SSL this should be changed to pods.Items[0].Status.PodIP + // port := memcachedCR.Spec.ServiceConfiguration.GetListenPort() + // memcachedCR.Status.Node = fmt.Sprintf("%s:%d", ip, port) + // memcachedCR.Status.Active = true + // } else { + // memcachedCR.Status.Active = false + // } + return r.client.Status().Update(context.Background(), memcachedCR) +} + +// newPodForCR returns a busybox pod with the same name/namespace as the cr +func newPodForCR(cr *contrailv1alpha1.ContrailMonitorStatus) *corev1.Pod { + labels := map[string]string{ + "app": cr.Name, + } + return &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: cr.Name + "-pod", + Namespace: cr.Namespace, + Labels: labels, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "busybox", + Image: "busybox", + Command: []string{"sleep", "3600"}, + }, + }, + }, + } +} + +func addResourcesToWatch(c controller.Controller, obj runtime.Object) error { + return c.Watch(&source.Kind{Type: obj}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &v1alpha1.Manager{}, + }) +} + +func (r *ReconcileContrailMonitorStatus) listReconcilePods(app string) (*corev1.PodList, error) { + pods := &corev1.PodList{} + labelSelector := labels.SelectorFromSet(map[string]string{"app": app}) + listOpts := client.ListOptions{LabelSelector: labelSelector} + if err := r.client.List(context.TODO(), pods, &listOpts); err != nil { + return &corev1.PodList{}, err + } + return pods, nil +} + + +///////////////////////////////////// + + +// { +// "metadata": {}, +// "items": [ +// { +// "kind": "Config", +// "apiVersion": "contrail.juniper.net/v1alpha1", +// "metadata": { +// "name": "config1", +// "namespace": "contrail", +// "selfLink": "/apis/contrail.juniper.net/v1alpha1/namespaces/contrail/configs/config1", +// "uid": "9bff99ec-926d-477f-b0c9-2961aeaeec58", +// "resourceVersion": "61089", +// "generation": 2, +// "creationTimestamp": "2020-07-24T06:10:35Z", +// "labels": { +// "contrail_cluster": "cluster1" +// }, +// "ownerReferences": [ +// { +// "apiVersion": "contrail.juniper.net/v1alpha1", +// "kind": "Manager", +// "name": "cluster1", +// "uid": "8bbde7a6-468a-4735-9ebb-e9d0f641574f", +// "controller": true, +// "blockOwnerDeletion": true +// }, +// { +// "apiVersion": "contrail.juniper.net/v1alpha1", +// "kind": "ContrailMonitorStatus", +// "name": "contrailmonitorstatus1", +// "uid": "bb50a962-27c6-4269-89da-35f564ea8da5", +// "controller": false, +// "blockOwnerDeletion": false +// } +// ] +// }, +// "spec": { +// "commonConfiguration": { +// "create": true, +// "nodeSelector": { +// "node-role.kubernetes.io/master": "" +// }, +// "hostNetwork": true, +// "replicas": 1 +// }, +// "serviceConfiguration": { +// "containers": [ +// { +// "name": "analyticsapi", +// "image": "registry:5000/contrail-nightly/contrail-analytics-api:2005.42" +// }, +// { +// "name": "api", +// "image": "registry:5000/contrail-nightly/contrail-controller-config-api:2005.42" +// }, +// { +// "name": "collector", +// "image": "registry:5000/contrail-nightly/contrail-analytics-collector:2005.42" +// }, +// { +// "name": "devicemanager", +// "image": "registry:5000/contrail-nightly/contrail-controller-config-devicemgr:2005.42" +// }, +// { +// "name": "dnsmasq", +// "image": "registry:5000/contrail-nightly/contrail-controller-config-dnsmasq:2005.42" +// }, +// { +// "name": "init", +// "image": "registry:5000/common-docker-third-party/contrail/python:3.8.2-alpine" +// }, +// { +// "name": "init2", +// "image": "registry:5000/common-docker-third-party/contrail/busybox:1.31" +// }, +// { +// "name": "nodeinit", +// "image": "registry:5000/contrail-nightly/contrail-node-init:2005.42" +// }, +// { +// "name": "schematransformer", +// "image": "registry:5000/contrail-nightly/contrail-controller-config-schema:2005.42" +// }, +// { +// "name": "servicemonitor", +// "image": "registry:5000/contrail-nightly/contrail-controller-config-svcmonitor:2005.42" +// }, +// { +// "name": "queryengine", +// "image": "registry:5000/contrail-nightly/contrail-analytics-query-engine:2005.42" +// }, +// { +// "name": "redis", +// "image": "registry:5000/common-docker-third-party/contrail/redis:4.0.2" +// }, +// { +// "name": "statusmonitor", +// "image": "registry:5000/contrail-operator/engprod-269421/contrail-statusmonitor:master.latest" +// } +// ], +// "cassandraInstance": "cassandra1", +// "zookeeperInstance": "zookeeper1", +// "logLevel": "SYS_DEBUG", +// "keystoneSecretName": "cluster1-admin-password", +// "keystoneInstance": "keystone", +// "authMode": "keystone", +// "storage": {} +// } +// }, +// "status": { +// "active": true, +// "nodes": { +// "config1-config-statefulset-0": "172.17.0.3" +// }, +// "ports": { +// "apiPort": "8082", +// "analyticsPort": "8081", +// "collectorPort": "8086", +// "redisPort": "6379" +// }, +// "configChanged": false, +// "serviceStatus": { +// "kind-control-plane": { +// "analyticsapi": { +// "moduleName": "contrail-analytics-api", +// "state": "Functional" +// }, +// "api": { +// "moduleName": "contrail-api", +// "state": "Functional" +// }, +// "collector": { +// "moduleName": "contrail-collector", +// "state": "Functional" +// }, +// "devicemanager": { +// "moduleName": "contrail-device-manager", +// "state": "Functional" +// }, +// "schema": { +// "moduleName": "contrail-schema", +// "state": "Functional" +// }, +// "svcmonitor": { +// "moduleName": "contrail-svc-monitor", +// "state": "Functional" +// } +// } +// } +// } +// } +// ] +// } + + + // configJSON, err := json.MarshalIndent(config, "", " ") + // if err != nil { + // return reconcile.Result{}, err + // } + // fmt.Printf("-----------\n %s\n", string(configJSON)) \ No newline at end of file diff --git a/pkg/controller/manager/manager_controller.go b/pkg/controller/manager/manager_controller.go index e66fa1984..bd11887d2 100644 --- a/pkg/controller/manager/manager_controller.go +++ b/pkg/controller/manager/manager_controller.go @@ -34,6 +34,7 @@ var resourcesList = []runtime.Object{ &v1alpha1.ProvisionManager{}, &v1alpha1.Config{}, &v1alpha1.Control{}, + &v1alpha1.ContrailMonitorStatus{}, &v1alpha1.Rabbitmq{}, &v1alpha1.Postgres{}, &v1alpha1.Command{}, @@ -1485,19 +1486,23 @@ func (r *ReconcileManager) Reconcile(request reconcile.Request) (reconcile.Resul return reconcile.Result{}, err } - if err = r.processCommand(instance); err != nil { - return reconcile.Result{}, err - } + // if err = r.processCommand(instance); err != nil { + // return reconcile.Result{}, err + // } - if err = r.processKeystone(instance); err != nil { - return reconcile.Result{}, err - } + // if err = r.processKeystone(instance); err != nil { + // return reconcile.Result{}, err + // } + + // if err = r.processSwift(instance); err != nil { + // return reconcile.Result{}, err + // } - if err = r.processSwift(instance); err != nil { + if err = r.processMemcached(instance); err != nil { return reconcile.Result{}, err } - if err = r.processMemcached(instance); err != nil { + if err = r.processContrailMonitorStatus(instance); err != nil { return reconcile.Result{}, err } @@ -1635,3 +1640,20 @@ func (r *ReconcileManager) processCSRSignerCaConfigMap(manager *v1alpha1.Manager return err } + +func (r *ReconcileManager) processContrailMonitorStatus(manager *v1alpha1.Manager) error { + if manager.Spec.Services.ContrailMonitorStatus == nil { + return nil + } + cmtatus := &v1alpha1.ContrailMonitorStatus{} + cmtatus.ObjectMeta = manager.Spec.Services.ContrailMonitorStatus.ObjectMeta + cmtatus.ObjectMeta.Namespace = manager.Namespace + _, err := controllerutil.CreateOrUpdate(context.Background(), r.client, cmtatus, func() error { + cmtatus.Spec = manager.Spec.Services.ContrailMonitorStatus.Spec + return controllerutil.SetControllerReference(manager, cmtatus, r.scheme) + }) + status := &v1alpha1.ServiceStatus{} + status.Active = &cmtatus.Status.Active + manager.Status.ContrailMonitorStatus = status + return err +}