diff --git a/deploy/1-create-operator.yaml b/deploy/1-create-operator.yaml index 5cced9868..0691cf375 100644 --- a/deploy/1-create-operator.yaml +++ b/deploy/1-create-operator.yaml @@ -65,6 +65,8 @@ rules: - swifts - memcacheds - fernetkeymanagers + - contrailmonitors + - contrailstatusmonitors verbs: - '*' - apiGroups: @@ -179,7 +181,7 @@ spec: listKind: CassandraList plural: cassandras singular: cassandra - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -365,7 +367,7 @@ spec: listKind: CommandList plural: commands singular: command - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -528,7 +530,7 @@ spec: listKind: ConfigList plural: configs singular: config - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -757,6 +759,136 @@ spec: --- apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition +metadata: + name: contrailmonitors.contrail.juniper.net +spec: + group: contrail.juniper.net + names: + kind: Contrailmonitor + listKind: ContrailmonitorList + plural: contrailmonitors + singular: contrailmonitor + scope: Namespaced + subresources: + status: {} + validation: + openAPIV3Schema: + description: Contrailmonitor is the Schema for the contrailmonitors 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: ContrailmonitorSpec defines the desired state of Contrailmonitor + properties: + serviceConfiguration: + 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: + 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 + webuiInstance: + type: string + zookeeperInstance: + type: string + type: object + required: + - serviceConfiguration + type: object + status: + description: ContrailmonitorStatus defines the observed state of Contrailmonitor + 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 + name: + type: string + required: + - name + type: object + type: object + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: contrailstatusmonitors.contrail.juniper.net +spec: + additionalPrinterColumns: + - JSONPath: .status + description: Number of instances in group + name: Status + type: string + group: contrail.juniper.net + names: + kind: Contrailstatusmonitor + listKind: ContrailstatusmonitorList + plural: contrailstatusmonitors + singular: contrailstatusmonitor + scope: Namespaced + subresources: {} + validation: + openAPIV3Schema: + description: Contrailstatusmonitor is the Schema for the contrailstatusmonitors + 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 + status: + type: string + 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: @@ -766,7 +898,7 @@ spec: listKind: ControlList plural: controls singular: control - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -1044,7 +1176,7 @@ spec: listKind: KeystoneList plural: keystones singular: keystone - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -1214,7 +1346,7 @@ spec: listKind: KubemanagerList plural: kubemanagers singular: kubemanager - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -1409,7 +1541,7 @@ spec: listKind: ManagerList plural: managers singular: manager - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -2081,6 +2213,76 @@ spec: type: object type: object type: object + contrailmonitor: + description: Contrailmonitor is the Schema for the contrailmonitors + 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: ContrailmonitorSpec defines the desired state of + Contrailmonitor + properties: + serviceConfiguration: + 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: + 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 + webuiInstance: + type: string + zookeeperInstance: + type: string + type: object + required: + - serviceConfiguration + type: object + status: + description: ContrailmonitorStatus defines the observed state + of Contrailmonitor + 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 + name: + type: string + required: + - name + type: object + type: object controls: items: description: Control is the Schema for the controls API. @@ -3762,7 +3964,19 @@ spec: replicas: format: int32 type: integer - serviceStatus: {} + serviceStatus: + additionalProperties: + additionalProperties: + properties: + moduleName: + type: string + state: + type: string + required: + - state + type: object + type: object + type: object type: object type: object zookeepers: @@ -3992,6 +4206,17 @@ spec: name: type: string type: object + contrailmonitor: + 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 @@ -4327,7 +4552,7 @@ spec: listKind: PostgresList plural: postgres singular: postgres - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -4582,7 +4807,7 @@ spec: listKind: RabbitmqList plural: rabbitmqs singular: rabbitmq - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -4771,7 +4996,7 @@ spec: listKind: SwiftProxyList plural: swiftproxies singular: swiftproxy - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -4938,7 +5163,7 @@ spec: listKind: SwiftList plural: swifts singular: swift - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -5170,7 +5395,7 @@ spec: listKind: SwiftStorageList plural: swiftstorages singular: swiftstorage - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -5340,7 +5565,7 @@ spec: listKind: VrouterList plural: vrouters singular: vrouter - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -5540,7 +5765,7 @@ spec: listKind: WebuiList plural: webuis singular: webui - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -5694,7 +5919,19 @@ spec: replicas: format: int32 type: integer - serviceStatus: {} + serviceStatus: + additionalProperties: + additionalProperties: + properties: + moduleName: + type: string + state: + type: string + required: + - state + type: object + type: object + type: object type: object type: object version: v1alpha1 @@ -5714,7 +5951,7 @@ spec: listKind: ZookeeperList plural: zookeepers singular: zookeeper - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_cassandras_crd.yaml b/deploy/crds/contrail.juniper.net_cassandras_crd.yaml index 7005a8609..1f9bb227c 100644 --- a/deploy/crds/contrail.juniper.net_cassandras_crd.yaml +++ b/deploy/crds/contrail.juniper.net_cassandras_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: CassandraList plural: cassandras singular: cassandra - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_commands_crd.yaml b/deploy/crds/contrail.juniper.net_commands_crd.yaml index d7c98f460..5c5798f1a 100644 --- a/deploy/crds/contrail.juniper.net_commands_crd.yaml +++ b/deploy/crds/contrail.juniper.net_commands_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: CommandList plural: commands singular: command - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_configs_crd.yaml b/deploy/crds/contrail.juniper.net_configs_crd.yaml index 62714b05a..53de73122 100644 --- a/deploy/crds/contrail.juniper.net_configs_crd.yaml +++ b/deploy/crds/contrail.juniper.net_configs_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: ConfigList plural: configs singular: config - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_contrailmonitors_crd.yaml b/deploy/crds/contrail.juniper.net_contrailmonitors_crd.yaml new file mode 100644 index 000000000..473eed294 --- /dev/null +++ b/deploy/crds/contrail.juniper.net_contrailmonitors_crd.yaml @@ -0,0 +1,85 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: contrailmonitors.contrail.juniper.net +spec: + group: contrail.juniper.net + names: + kind: Contrailmonitor + listKind: ContrailmonitorList + plural: contrailmonitors + singular: contrailmonitor + scope: Namespaced + subresources: + status: {} + validation: + openAPIV3Schema: + description: Contrailmonitor is the Schema for the contrailmonitors 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: ContrailmonitorSpec defines the desired state of Contrailmonitor + properties: + serviceConfiguration: + 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: + 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 + webuiInstance: + type: string + zookeeperInstance: + type: string + type: object + required: + - serviceConfiguration + type: object + status: + description: ContrailmonitorStatus defines the observed state of Contrailmonitor + 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 + name: + type: string + required: + - name + type: object + type: object + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true diff --git a/deploy/crds/contrail.juniper.net_contrailstatusmonitors_crd.yaml b/deploy/crds/contrail.juniper.net_contrailstatusmonitors_crd.yaml new file mode 100644 index 000000000..823c8b875 --- /dev/null +++ b/deploy/crds/contrail.juniper.net_contrailstatusmonitors_crd.yaml @@ -0,0 +1,43 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: contrailstatusmonitors.contrail.juniper.net +spec: + additionalPrinterColumns: + - JSONPath: .status + description: Number of instances in group + name: Status + type: string + group: contrail.juniper.net + names: + kind: Contrailstatusmonitor + listKind: ContrailstatusmonitorList + plural: contrailstatusmonitors + singular: contrailstatusmonitor + scope: Namespaced + subresources: {} + validation: + openAPIV3Schema: + description: Contrailstatusmonitor is the Schema for the contrailstatusmonitors + 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 + status: + type: string + type: object + version: v1alpha1 + versions: + - name: v1alpha1 + served: true + storage: true diff --git a/deploy/crds/contrail.juniper.net_controls_crd.yaml b/deploy/crds/contrail.juniper.net_controls_crd.yaml index e83ba8616..60764a006 100644 --- a/deploy/crds/contrail.juniper.net_controls_crd.yaml +++ b/deploy/crds/contrail.juniper.net_controls_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: ControlList plural: controls singular: control - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_keystones_crd.yaml b/deploy/crds/contrail.juniper.net_keystones_crd.yaml index 22a7aee6e..295c6516e 100644 --- a/deploy/crds/contrail.juniper.net_keystones_crd.yaml +++ b/deploy/crds/contrail.juniper.net_keystones_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: KeystoneList plural: keystones singular: keystone - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_kubemanagers_crd.yaml b/deploy/crds/contrail.juniper.net_kubemanagers_crd.yaml index 6caec6770..4331f6ce6 100644 --- a/deploy/crds/contrail.juniper.net_kubemanagers_crd.yaml +++ b/deploy/crds/contrail.juniper.net_kubemanagers_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: KubemanagerList plural: kubemanagers singular: kubemanager - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_managers_crd.yaml b/deploy/crds/contrail.juniper.net_managers_crd.yaml index 2055b1dd7..8bfb76daf 100644 --- a/deploy/crds/contrail.juniper.net_managers_crd.yaml +++ b/deploy/crds/contrail.juniper.net_managers_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: ManagerList plural: managers singular: manager - scope: Namespaced + scope: "" subresources: status: {} validation: @@ -681,6 +681,76 @@ spec: type: object type: object type: object + contrailmonitor: + description: Contrailmonitor is the Schema for the contrailmonitors + 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: ContrailmonitorSpec defines the desired state of + Contrailmonitor + properties: + serviceConfiguration: + 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: + 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 + webuiInstance: + type: string + zookeeperInstance: + type: string + type: object + required: + - serviceConfiguration + type: object + status: + description: ContrailmonitorStatus defines the observed state + of Contrailmonitor + 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 + name: + type: string + required: + - name + type: object + type: object controls: items: description: Control is the Schema for the controls API. @@ -2604,6 +2674,17 @@ spec: name: type: string type: object + contrailmonitor: + 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_postgres_crd.yaml b/deploy/crds/contrail.juniper.net_postgres_crd.yaml index 40be47b11..c31a828fd 100644 --- a/deploy/crds/contrail.juniper.net_postgres_crd.yaml +++ b/deploy/crds/contrail.juniper.net_postgres_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: PostgresList plural: postgres singular: postgres - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_rabbitmqs_crd.yaml b/deploy/crds/contrail.juniper.net_rabbitmqs_crd.yaml index 5ec6fa419..d9be8f45b 100644 --- a/deploy/crds/contrail.juniper.net_rabbitmqs_crd.yaml +++ b/deploy/crds/contrail.juniper.net_rabbitmqs_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: RabbitmqList plural: rabbitmqs singular: rabbitmq - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_swiftproxies_crd.yaml b/deploy/crds/contrail.juniper.net_swiftproxies_crd.yaml index 2d1ac3ad7..e5a66458f 100644 --- a/deploy/crds/contrail.juniper.net_swiftproxies_crd.yaml +++ b/deploy/crds/contrail.juniper.net_swiftproxies_crd.yaml @@ -25,7 +25,7 @@ spec: listKind: SwiftProxyList plural: swiftproxies singular: swiftproxy - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_swifts_crd.yaml b/deploy/crds/contrail.juniper.net_swifts_crd.yaml index 4b395cb54..df007871f 100644 --- a/deploy/crds/contrail.juniper.net_swifts_crd.yaml +++ b/deploy/crds/contrail.juniper.net_swifts_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: SwiftList plural: swifts singular: swift - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_swiftstorages_crd.yaml b/deploy/crds/contrail.juniper.net_swiftstorages_crd.yaml index c1cf85b83..e73d5c2ff 100644 --- a/deploy/crds/contrail.juniper.net_swiftstorages_crd.yaml +++ b/deploy/crds/contrail.juniper.net_swiftstorages_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: SwiftStorageList plural: swiftstorages singular: swiftstorage - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_v1alpha1_contrailmonitor_cr.yaml b/deploy/crds/contrail.juniper.net_v1alpha1_contrailmonitor_cr.yaml new file mode 100644 index 000000000..d7fe060f3 --- /dev/null +++ b/deploy/crds/contrail.juniper.net_v1alpha1_contrailmonitor_cr.yaml @@ -0,0 +1,7 @@ +apiVersion: contrail.juniper.net/v1alpha1 +kind: Contrailmonitor +metadata: + name: example-contrailmonitor +spec: + # Add fields here + size: 3 diff --git a/deploy/crds/contrail.juniper.net_v1alpha1_contrailstatusmonitor_cr.yaml b/deploy/crds/contrail.juniper.net_v1alpha1_contrailstatusmonitor_cr.yaml new file mode 100644 index 000000000..c652c26ff --- /dev/null +++ b/deploy/crds/contrail.juniper.net_v1alpha1_contrailstatusmonitor_cr.yaml @@ -0,0 +1,11 @@ +apiVersion: contrail.juniper.net/v1alpha1 +kind: Contrailstatusmonitor +metadata: + name: cassandra1 +status: functional +--- +apiVersion: contrail.juniper.net/v1alpha1 +kind: Contrailstatusmonitor +metadata: + name: zookeeper1 +status: non-functional \ No newline at end of file diff --git a/deploy/crds/contrail.juniper.net_vrouters_crd.yaml b/deploy/crds/contrail.juniper.net_vrouters_crd.yaml index 628630753..0d94074f9 100644 --- a/deploy/crds/contrail.juniper.net_vrouters_crd.yaml +++ b/deploy/crds/contrail.juniper.net_vrouters_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: VrouterList plural: vrouters singular: vrouter - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_webuis_crd.yaml b/deploy/crds/contrail.juniper.net_webuis_crd.yaml index 5a4bafccf..f93fec53e 100644 --- a/deploy/crds/contrail.juniper.net_webuis_crd.yaml +++ b/deploy/crds/contrail.juniper.net_webuis_crd.yaml @@ -22,7 +22,7 @@ spec: listKind: WebuiList plural: webuis singular: webui - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/crds/contrail.juniper.net_zookeepers_crd.yaml b/deploy/crds/contrail.juniper.net_zookeepers_crd.yaml index 0775532db..b79517f27 100644 --- a/deploy/crds/contrail.juniper.net_zookeepers_crd.yaml +++ b/deploy/crds/contrail.juniper.net_zookeepers_crd.yaml @@ -9,7 +9,7 @@ spec: listKind: ZookeeperList plural: zookeepers singular: zookeeper - scope: Namespaced + scope: "" subresources: status: {} validation: diff --git a/deploy/role.yaml b/deploy/role.yaml index 0975cb375..bc3e363da 100644 --- a/deploy/role.yaml +++ b/deploy/role.yaml @@ -60,6 +60,8 @@ rules: - swifts - memcacheds - fernetkeymanagers + - contrailmonitors + - contrailstatusmonitors verbs: - '*' - apiGroups: diff --git a/pkg/apis/contrail/v1alpha1/BUILD.bazel b/pkg/apis/contrail/v1alpha1/BUILD.bazel index 27aba58b5..17deb4b6b 100644 --- a/pkg/apis/contrail/v1alpha1/BUILD.bazel +++ b/pkg/apis/contrail/v1alpha1/BUILD.bazel @@ -7,6 +7,8 @@ go_library( "cassandra_types.go", "command_types.go", "config_types.go", + "contrailmonitor_types.go", + "contrailstatusmonitor_types.go", "control_types.go", "defaults.go", "doc.go", diff --git a/pkg/apis/contrail/v1alpha1/contrailmonitor_types.go b/pkg/apis/contrail/v1alpha1/contrailmonitor_types.go new file mode 100644 index 000000000..4dadc14ba --- /dev/null +++ b/pkg/apis/contrail/v1alpha1/contrailmonitor_types.go @@ -0,0 +1,67 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// ContrailmonitorSpec defines the desired state of Contrailmonitor +type ContrailmonitorSpec struct { + // 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 + ServiceConfiguration ContrailmonitorConfiguration `json:"serviceConfiguration"` +} + +// ContrailmonitorConfiguration is the Spec for the Contrailmonitor API. +// +k8s:openapi-gen=true +type ContrailmonitorConfiguration 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"` + WebuiInstance string `json:"webuiInstance,omitempty"` +} + +// ContrailmonitorStatus defines the observed state of Contrailmonitor +type ContrailmonitorStatus 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-v1.book.kubebuilder.io/beyond_basics/generating_crd.html + Active bool `json:"active,omitempty"` + Name string `json:"name"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Contrailmonitor is the Schema for the contrailmonitors API +// +kubebuilder:subresource:status +// +kubebuilder:resource:path=contrailmonitors,scope=Namespaced +type Contrailmonitor struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ContrailmonitorSpec `json:"spec,omitempty"` + Status ContrailmonitorStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ContrailmonitorList contains a list of Contrailmonitor +type ContrailmonitorList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Contrailmonitor `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Contrailmonitor{}, &ContrailmonitorList{}) +} diff --git a/pkg/apis/contrail/v1alpha1/contrailstatusmonitor_types.go b/pkg/apis/contrail/v1alpha1/contrailstatusmonitor_types.go new file mode 100644 index 000000000..db9eaf8fd --- /dev/null +++ b/pkg/apis/contrail/v1alpha1/contrailstatusmonitor_types.go @@ -0,0 +1,30 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Contrailstatusmonitor is the Schema for the contrailstatusmonitors API +// +kubebuilder:resource:path=contrailstatusmonitors,scope=Namespaced +// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status",description="Number of instances in group" +type Contrailstatusmonitor struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Status string `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ContrailstatusmonitorList contains a list of Contrailstatusmonitor +type ContrailstatusmonitorList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Contrailstatusmonitor `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Contrailstatusmonitor{}, &ContrailstatusmonitorList{}) +} diff --git a/pkg/apis/contrail/v1alpha1/manager_types.go b/pkg/apis/contrail/v1alpha1/manager_types.go index 12e47fa82..1c9c968a9 100644 --- a/pkg/apis/contrail/v1alpha1/manager_types.go +++ b/pkg/apis/contrail/v1alpha1/manager_types.go @@ -37,6 +37,7 @@ type Services struct { Keystone *Keystone `json:"keystone,omitempty"` Swift *Swift `json:"swift,omitempty"` Memcached *Memcached `json:"memcached,omitempty"` + Contrailmonitor *Contrailmonitor `json:"contrailmonitor,omitempty"` } // ManagerStatus defines the observed state of Manager. @@ -60,6 +61,7 @@ type ManagerStatus struct { Swift *ServiceStatus `json:"swift,omitempty"` Command *ServiceStatus `json:"command,omitempty"` Memcached *ServiceStatus `json:"memcached,omitempty"` + Contrailmonitor *ServiceStatus `json:"contrailmonitor,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.Contrailmonitor != nil && !m.Status.Contrailmonitor.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 d0c78174c..605153d81 100644 --- a/pkg/apis/contrail/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/contrail/v1alpha1/zz_generated.deepcopy.go @@ -858,6 +858,175 @@ 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 *Contrailmonitor) DeepCopyInto(out *Contrailmonitor) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Contrailmonitor. +func (in *Contrailmonitor) DeepCopy() *Contrailmonitor { + if in == nil { + return nil + } + out := new(Contrailmonitor) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Contrailmonitor) 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 *ContrailmonitorConfiguration) DeepCopyInto(out *ContrailmonitorConfiguration) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailmonitorConfiguration. +func (in *ContrailmonitorConfiguration) DeepCopy() *ContrailmonitorConfiguration { + if in == nil { + return nil + } + out := new(ContrailmonitorConfiguration) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContrailmonitorList) DeepCopyInto(out *ContrailmonitorList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Contrailmonitor, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailmonitorList. +func (in *ContrailmonitorList) DeepCopy() *ContrailmonitorList { + if in == nil { + return nil + } + out := new(ContrailmonitorList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ContrailmonitorList) 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 *ContrailmonitorSpec) DeepCopyInto(out *ContrailmonitorSpec) { + *out = *in + out.ServiceConfiguration = in.ServiceConfiguration + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailmonitorSpec. +func (in *ContrailmonitorSpec) DeepCopy() *ContrailmonitorSpec { + if in == nil { + return nil + } + out := new(ContrailmonitorSpec) + in.DeepCopyInto(out) + 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 + 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 +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Contrailstatusmonitor) DeepCopyInto(out *Contrailstatusmonitor) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Contrailstatusmonitor. +func (in *Contrailstatusmonitor) DeepCopy() *Contrailstatusmonitor { + if in == nil { + return nil + } + out := new(Contrailstatusmonitor) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Contrailstatusmonitor) 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 *ContrailstatusmonitorList) DeepCopyInto(out *ContrailstatusmonitorList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Contrailstatusmonitor, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContrailstatusmonitorList. +func (in *ContrailstatusmonitorList) DeepCopy() *ContrailstatusmonitorList { + if in == nil { + return nil + } + out := new(ContrailstatusmonitorList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ContrailstatusmonitorList) 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 *Control) DeepCopyInto(out *Control) { *out = *in @@ -1795,6 +1964,11 @@ func (in *ManagerStatus) DeepCopyInto(out *ManagerStatus) { *out = new(ServiceStatus) (*in).DeepCopyInto(*out) } + if in.Contrailmonitor != nil { + in, out := &in.Contrailmonitor, &out.Contrailmonitor + *out = new(ServiceStatus) + (*in).DeepCopyInto(*out) + } if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions *out = make([]ManagerCondition, len(*in)) @@ -2557,6 +2731,11 @@ func (in *Services) DeepCopyInto(out *Services) { *out = new(Memcached) (*in).DeepCopyInto(*out) } + if in.Contrailmonitor != nil { + in, out := &in.Contrailmonitor, &out.Contrailmonitor + *out = new(Contrailmonitor) + (*in).DeepCopyInto(*out) + } return } diff --git a/pkg/controller/BUILD.bazel b/pkg/controller/BUILD.bazel index 23d9995ba..de6398c0f 100644 --- a/pkg/controller/BUILD.bazel +++ b/pkg/controller/BUILD.bazel @@ -6,6 +6,7 @@ go_library( "add_cassandra.go", "add_command.go", "add_config.go", + "add_contrailmonitor.go", "add_control.go", "add_fernetkeymanager.go", "add_keystone.go", @@ -27,6 +28,7 @@ go_library( "//pkg/controller/cassandra:go_default_library", "//pkg/controller/command:go_default_library", "//pkg/controller/config:go_default_library", + "//pkg/controller/contrailmonitor:go_default_library", "//pkg/controller/control:go_default_library", "//pkg/controller/fernetkeymanager:go_default_library", "//pkg/controller/keystone:go_default_library", diff --git a/pkg/controller/add_contrailmonitor.go b/pkg/controller/add_contrailmonitor.go new file mode 100644 index 000000000..d0e0ac45c --- /dev/null +++ b/pkg/controller/add_contrailmonitor.go @@ -0,0 +1,10 @@ +package controller + +import ( + "github.com/Juniper/contrail-operator/pkg/controller/contrailmonitor" +) + +func init() { + // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. + AddToManagerFuncs = append(AddToManagerFuncs, contrailmonitor.Add) +} diff --git a/pkg/controller/contrailmonitor/BUILD.bazel b/pkg/controller/contrailmonitor/BUILD.bazel new file mode 100644 index 000000000..f41c7b8b9 --- /dev/null +++ b/pkg/controller/contrailmonitor/BUILD.bazel @@ -0,0 +1,25 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "go_default_library", + srcs = ["contrailmonitor_controller.go"], + importpath = "github.com/Juniper/contrail-operator/pkg/controller/contrailmonitor", + visibility = ["//visibility:public"], + deps = [ + "//pkg/apis/contrail/v1alpha1:go_default_library", + "//pkg/k8s:go_default_library", + "@io_k8s_api//core/v1:go_default_library", + "@io_k8s_apimachinery//pkg/api/errors: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_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/log:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/reconcile:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/source:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/manager:go_default_library", + ], +) diff --git a/pkg/controller/contrailmonitor/contrailmonitor_controller.go b/pkg/controller/contrailmonitor/contrailmonitor_controller.go new file mode 100644 index 000000000..6f3f9ddc0 --- /dev/null +++ b/pkg/controller/contrailmonitor/contrailmonitor_controller.go @@ -0,0 +1,450 @@ +package contrailmonitor + +import ( + "context" + + 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" +) + +var log = logf.Log.WithName("controller_contrailmonitor") + + +// Add creates a new Contrailmonitor 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 &ReconcileContrailmonitor{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("contrailmonitor-controller", mgr, controller.Options{Reconciler: r}) + if err != nil { + return err + } + + // Watch for changes to primary resource Contrailmonitor + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Contrailmonitor{}}, &handler.EnqueueRequestForObject{}) + if 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 Contrailmonitor + err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Postgres{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Memcached{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Cassandra{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Control{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Config{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Keystone{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Zookeeper{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Rabbitmq{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + err = c.Watch(&source.Kind{Type: &contrailv1alpha1.Webui{}}, &handler.EnqueueRequestForOwner{ + OwnerType: &contrailv1alpha1.Contrailmonitor{}, + }) + if err != nil { + return err + } + return nil +} + +// blank assignment to verify that ReconcileContrailmonitor implements reconcile.Reconciler +var _ reconcile.Reconciler = &ReconcileContrailmonitor{} + +// ReconcileContrailmonitor reconciles a Contrailmonitor object +type ReconcileContrailmonitor 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 reads that state of the cluster for a Contrailmonitor object and makes changes based on the state read +// and what is in the Contrailmonitor.Spec +// TODO(user): Modify this Reconcile function to implement your Controller logic. This example creates +// a Pod as an example +// Note: +// The Controller will requeue the Request to be processed again if the returned error is non-nil or +// Result.Requeue is true, otherwise upon completion it will remove the work from the queue. +func (r *ReconcileContrailmonitor) Reconcile(request reconcile.Request) (reconcile.Result, error) { + reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) + reqLogger.Info("Reconciling Contrailmonitor") + + // Fetch the Contrailmonitor instance + instance := &contrailv1alpha1.Contrailmonitor{} + err := r.client.Get(context.TODO(), request.NamespacedName, instance) + if err != nil { + if errors.IsNotFound(err) { + // Request object not found, could have been deleted after reconcile request. + // Owned objects are automatically garbage collected. For additional cleanup logic use finalizers. + // Return and don't requeue + return reconcile.Result{}, nil + } + // Error reading the object - requeue the request. + return reconcile.Result{}, err + } + + if !instance.GetDeletionTimestamp().IsZero() { + return reconcile.Result{}, nil + } + instance.Status.Name = "contrailmonitor" + instance.Status.Active = true + psql, err := r.getPostgres(instance) + if err != nil { + return reconcile.Result{}, err + } + + serIns := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: psql.Name, Namespace: "contrail"}} + + if psql.Status.Active { + serIns.Status = "Active" + } else { + serIns.Status = "NotActive" + } + _, err = controllerutil.CreateOrUpdate(context.Background(), r.client, serIns, func() error { + return controllerutil.SetControllerReference(instance, serIns, r.scheme) + }) + if err != nil { + return reconcile.Result{}, nil + } + + memcached, err := r.getMemcached(instance) + if err != nil { + return reconcile.Result{}, err + } + + serIns1 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: memcached.Name, Namespace: "contrail"}} + + if memcached.Status.Active { + serIns1.Status = "Active" + } else { + serIns1.Status = "NotActive" + } + _, err = controllerutil.CreateOrUpdate(context.Background(), r.client, serIns1, func() error { + return controllerutil.SetControllerReference(instance, serIns1, r.scheme) + }) + if err != nil { + return reconcile.Result{}, nil + } + + keystone, err := r.getKeystone(instance) + if err != nil { + return reconcile.Result{}, err + } + + serIns2 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: keystone.Name, Namespace: "contrail"}} + + if keystone.Status.Active { + serIns2.Status = "Active" + } else { + serIns2.Status = "NotActive" + } + _, err = controllerutil.CreateOrUpdate(context.Background(), r.client, serIns2, func() error { + return controllerutil.SetControllerReference(instance, serIns2, r.scheme) + }) + if err != nil { + return reconcile.Result{}, nil + } + + rabbitmq, err := r.getRabbitmq(instance) + if err != nil { + return reconcile.Result{}, err + } + + serIns6 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: rabbitmq.Name, Namespace: "contrail"}} + + if rabbitmq.Status.Active == nil { + serIns6.Status = "NotActive" + } else { + serIns6.Status = "Active" + } + _, err = controllerutil.CreateOrUpdate(context.Background(), r.client, serIns6, func() error { + return controllerutil.SetControllerReference(instance, serIns6, r.scheme) + }) + if err != nil { + return reconcile.Result{}, nil + } + + zookeeper, err := r.getZookeeper(instance) + if err != nil { + return reconcile.Result{}, err + } + + zookeeperActive := zookeeper.IsActive(instance.Spec.ServiceConfiguration.ZookeeperInstance, request.Namespace, r.client) + serIns5 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: zookeeper.Name, Namespace: "contrail"}} + + if zookeeper.Status.Active == nil || !zookeeperActive { + serIns5.Status = "NotActive" + } else { + serIns5.Status = "Active" + } + _, err = controllerutil.CreateOrUpdate(context.Background(), r.client, serIns5, func() error { + return controllerutil.SetControllerReference(instance, serIns5, r.scheme) + }) + if err != nil { + return reconcile.Result{}, nil + } + + cassandra, err := r.getCassandra(instance) + if err != nil { + return reconcile.Result{}, err + } + + cassandraActive := cassandra.IsActive(instance.Spec.ServiceConfiguration.CassandraInstance, request.Namespace, r.client) + serIns4 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: cassandra.Name, Namespace: "contrail"}} + if cassandra.Status.Active == nil || !cassandraActive { + serIns4.Status = "NotActive" + } else { + serIns4.Status = "Active" + } + _, err = controllerutil.CreateOrUpdate(context.Background(), r.client, serIns4, func() error { + return controllerutil.SetControllerReference(instance, serIns4, r.scheme) + }) + if err != nil { + return reconcile.Result{}, nil + } + + wklist, err := r.getWebuilist() + if err != nil { + return reconcile.Result{}, err + } + wcount := len(wklist.Items) + if wcount > 0 { + for i := 0; i < wcount; i++ { + for _, value := range wklist.Items[i].Status.ServiceStatus { + for _, n := range value { + serIns8 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: n.ModuleName, Namespace: "contrail"}} + + serIns8.Status = n.ModuleState + _, err := controllerutil.CreateOrUpdate(context.Background(), r.client, serIns8, func() error { + return controllerutil.SetControllerReference(instance, serIns8, r.scheme) + }) + if err != nil { + return reconcile.Result{}, err + } + } + } + } + } else { + + serIns8 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: "Webui", Namespace: "contrail"}} + + serIns8.Status = "NotActive" + _, err := controllerutil.CreateOrUpdate(context.Background(), r.client, serIns8, func() error { + return controllerutil.SetControllerReference(instance, serIns8, r.scheme) + }) + if err != nil { + return reconcile.Result{}, err + } + + } + + clist, err := r.getConfiglist() + if err != nil { + return reconcile.Result{}, err + } + ccount := len(clist.Items) + if ccount > 0 { + for j := 0; j < ccount; j++ { + for _, value := range clist.Items[j].Status.ServiceStatus { + for _, n := range value { + serIns7 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: n.ModuleName, Namespace: "contrail"}} + + serIns7.Status = n.ModuleState + _, err := controllerutil.CreateOrUpdate(context.Background(), r.client, serIns7, func() error { + return controllerutil.SetControllerReference(instance, serIns7, r.scheme) + }) + if err != nil { + return reconcile.Result{}, err + } + } + } + } + } else { + serIns7 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: "config", Namespace: "contrail"}} + + serIns7.Status = "NotActive" + _, err := controllerutil.CreateOrUpdate(context.Background(), r.client, serIns7, func() error { + return controllerutil.SetControllerReference(instance, serIns7, r.scheme) + }) + if err != nil { + return reconcile.Result{}, err + } + } + provisionmanager, err := r.getProvisionmanager(instance) + if err != nil { + return reconcile.Result{}, err + } + serIns3 := &contrailv1alpha1.Contrailstatusmonitor{ObjectMeta: metav1.ObjectMeta{Name: provisionmanager.Name, Namespace: "contrail"}} + + if provisionmanager.Status.Active == nil { + serIns3.Status = "NotActive" + } else { + serIns3.Status = "Active" + } + + _, err = controllerutil.CreateOrUpdate(context.Background(), r.client, serIns3, func() error { + return controllerutil.SetControllerReference(instance, serIns3, r.scheme) + }) + if err != nil { + return reconcile.Result{}, nil + } + + return reconcile.Result{}, nil +} + +func (r *ReconcileContrailmonitor) getPostgres(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.Postgres, error) { + psql := &contrailv1alpha1.Postgres{} + name := types.NamespacedName{Namespace: cr.Namespace, + Name: cr.Spec.ServiceConfiguration.PostgresInstance} + err := r.client.Get(context.Background(), name, psql) + return psql, err +} + +func (r *ReconcileContrailmonitor) getMemcached(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.Memcached, error) { + 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 *ReconcileContrailmonitor) getZookeeper(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.Zookeeper, error) { + + 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 *ReconcileContrailmonitor) getCassandra(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.Cassandra, error) { + 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 *ReconcileContrailmonitor) getKeystone(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.Keystone, error) { + + 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 *ReconcileContrailmonitor) getRabbitmq(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.Rabbitmq, error) { + 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 *ReconcileContrailmonitor) getProvisionmanager(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.ProvisionManager, error) { + + 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 *ReconcileContrailmonitor) getConfig(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.Config, error) { + 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 +} + +func (r *ReconcileContrailmonitor) getConfiglist() (*contrailv1alpha1.ConfigList, error) { + listOps := &client.ListOptions{Namespace: "contrail"} + clist := &contrailv1alpha1.ConfigList{} + err := r.client.List(context.TODO(), clist, listOps) + return clist, err +} + +func (r *ReconcileContrailmonitor) getWebui(cr *contrailv1alpha1.Contrailmonitor) (*contrailv1alpha1.Webui, error) { + key := &contrailv1alpha1.Webui{} + name := types.NamespacedName{Namespace: cr.Namespace, Name: cr.Spec.ServiceConfiguration.WebuiInstance} + err := r.client.Get(context.Background(), name, key) + return key, err +} + +func (r *ReconcileContrailmonitor) getWebuilist() (*contrailv1alpha1.WebuiList, error) { + listOps := &client.ListOptions{Namespace: "contrail"} + wlist := &contrailv1alpha1.WebuiList{} + err := r.client.List(context.TODO(), wlist, listOps) + return wlist, err + +} diff --git a/pkg/controller/manager/manager_controller.go b/pkg/controller/manager/manager_controller.go index 8147742d8..d792f3c8d 100644 --- a/pkg/controller/manager/manager_controller.go +++ b/pkg/controller/manager/manager_controller.go @@ -43,6 +43,7 @@ var resourcesList = []runtime.Object{ &v1alpha1.Memcached{}, &v1alpha1.Vrouter{}, &v1alpha1.Kubemanager{}, + &v1alpha1.Contrailmonitor{}, &corev1.ConfigMap{}, } @@ -1507,6 +1508,10 @@ func (r *ReconcileManager) Reconcile(request reconcile.Request) (reconcile.Resul return reconcile.Result{}, err } + if err = r.processContrailmonitor(instance); err != nil { + return reconcile.Result{}, err + } + r.setConditions(instance) err = r.client.Status().Update(context.TODO(), instance) @@ -1667,3 +1672,20 @@ func (r *ReconcileManager) processCSRSignerCaConfigMap(manager *v1alpha1.Manager return err } + +func (r *ReconcileManager) processContrailmonitor(manager *v1alpha1.Manager) error { + if manager.Spec.Services.Contrailmonitor == nil { + return nil + } + cms := &v1alpha1.Contrailmonitor{} + cms.ObjectMeta = manager.Spec.Services.Contrailmonitor.ObjectMeta + cms.ObjectMeta.Namespace = manager.Namespace + _, err := controllerutil.CreateOrUpdate(context.Background(), r.client, cms, func() error { + cms.Spec = manager.Spec.Services.Contrailmonitor.Spec + return controllerutil.SetControllerReference(manager, cms, r.scheme) + }) + status := &v1alpha1.ServiceStatus{} + status.Active = &cms.Status.Active + manager.Status.Contrailmonitor = status + return err +} diff --git a/test/env/deploy/cluster.yaml b/test/env/deploy/cluster.yaml index 583011b7a..d27f22984 100644 --- a/test/env/deploy/cluster.yaml +++ b/test/env/deploy/cluster.yaml @@ -43,25 +43,25 @@ spec: keystoneInstance: keystone containers: - name: analyticsapi - image: registry:5000/contrail-nightly/contrail-analytics-api:master-latest + image: registry:5000/contrail-nightly/contrail-analytics-api:2005.42 - name: api - image: registry:5000/contrail-nightly/contrail-controller-config-api:master-latest + image: registry:5000/contrail-nightly/contrail-controller-config-api:2005.42 - name: collector - image: registry:5000/contrail-nightly/contrail-analytics-collector:master-latest + image: registry:5000/contrail-nightly/contrail-analytics-collector:2005.42 - name: devicemanager - image: registry:5000/contrail-nightly/contrail-controller-config-devicemgr:master-latest + image: registry:5000/contrail-nightly/contrail-controller-config-devicemgr:2005.42 - name: dnsmasq - image: registry:5000/contrail-nightly/contrail-controller-config-dnsmasq:master-latest + 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: schematransformer - image: registry:5000/contrail-nightly/contrail-controller-config-schema:master-latest + image: registry:5000/contrail-nightly/contrail-controller-config-schema:2005.42 - name: servicemonitor - image: registry:5000/contrail-nightly/contrail-controller-config-svcmonitor:master-latest + image: registry:5000/contrail-nightly/contrail-controller-config-svcmonitor:2005.42 - name: queryengine - image: registry:5000/contrail-nightly/contrail-analytics-query-engine:master-latest + 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 @@ -246,6 +246,20 @@ spec: containers: - name: memcached image: "registry:5000/common-docker-third-party/contrail/centos-binary-memcached:train-2005" + contrailmonitor: + metadata: + labels: + contrail_cluster: cluster1 + name: contrailmonitor + spec: + serviceConfiguration: + memcachedInstance: "memcached" + postgresInstance: "postgres" + keystoneInstance: "keystone" + cassandraInstance: "cassandra1" + rabbitmqInstance: "rabbitmq1" + zookeeperInstance: "zookeeper1" + provisionmanagerInstance: "provmanager1" swift: metadata: name: swift