diff --git a/deploy/crds/enterprise.splunk.com_clustermasters_crd.yaml b/deploy/crds/enterprise.splunk.com_clustermasters_crd.yaml index 8d2c968be..5c0d0bdfc 100644 --- a/deploy/crds/enterprise.splunk.com_clustermasters_crd.yaml +++ b/deploy/crds/enterprise.splunk.com_clustermasters_crd.yaml @@ -856,6 +856,43 @@ spec: licenseUrl: description: Full path or URL for a Splunk Enterprise license file type: string + monitoringConsoleRef: + description: MonitoringConsoleRef refers to a Splunk Enterprise monitoring + console managed by the operator within Kubernetes + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: 'If referring to a piece of an object instead of + an entire object, this string should contain a valid JSON/Go + field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within + a pod, this would take on a value like: "spec.containers{name}" + (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" + (container with index 2 in this pod). This syntax is chosen + only to have some well-defined way of referencing a part of + an object. TODO: this design is not final and this field is + subject to change in the future.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + type: string + resourceVersion: + description: 'Specific resourceVersion to which this reference + is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' + type: string + uid: + description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + type: string + type: object resources: description: resource requirements for the pod containers properties: diff --git a/deploy/crds/enterprise.splunk.com_indexerclusters_crd.yaml b/deploy/crds/enterprise.splunk.com_indexerclusters_crd.yaml index a45fa2b16..7ac676eb7 100644 --- a/deploy/crds/enterprise.splunk.com_indexerclusters_crd.yaml +++ b/deploy/crds/enterprise.splunk.com_indexerclusters_crd.yaml @@ -875,6 +875,43 @@ spec: licenseUrl: description: Full path or URL for a Splunk Enterprise license file type: string + monitoringConsoleRef: + description: MonitoringConsoleRef refers to a Splunk Enterprise monitoring + console managed by the operator within Kubernetes + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: 'If referring to a piece of an object instead of + an entire object, this string should contain a valid JSON/Go + field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within + a pod, this would take on a value like: "spec.containers{name}" + (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" + (container with index 2 in this pod). This syntax is chosen + only to have some well-defined way of referencing a part of + an object. TODO: this design is not final and this field is + subject to change in the future.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + type: string + resourceVersion: + description: 'Specific resourceVersion to which this reference + is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' + type: string + uid: + description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + type: string + type: object replicas: description: Number of search head pods; a search head cluster will be created if > 1 diff --git a/deploy/crds/enterprise.splunk.com_licensemasters_crd.yaml b/deploy/crds/enterprise.splunk.com_licensemasters_crd.yaml index e0e619471..2feffd584 100644 --- a/deploy/crds/enterprise.splunk.com_licensemasters_crd.yaml +++ b/deploy/crds/enterprise.splunk.com_licensemasters_crd.yaml @@ -861,6 +861,43 @@ spec: licenseUrl: description: Full path or URL for a Splunk Enterprise license file type: string + monitoringConsoleRef: + description: MonitoringConsoleRef refers to a Splunk Enterprise monitoring + console managed by the operator within Kubernetes + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: 'If referring to a piece of an object instead of + an entire object, this string should contain a valid JSON/Go + field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within + a pod, this would take on a value like: "spec.containers{name}" + (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" + (container with index 2 in this pod). This syntax is chosen + only to have some well-defined way of referencing a part of + an object. TODO: this design is not final and this field is + subject to change in the future.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + type: string + resourceVersion: + description: 'Specific resourceVersion to which this reference + is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' + type: string + uid: + description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + type: string + type: object resources: description: resource requirements for the pod containers properties: diff --git a/deploy/crds/enterprise.splunk.com_monitoringconsoles_crd.yaml b/deploy/crds/enterprise.splunk.com_monitoringconsoles_crd.yaml index 3585f2c18..961d15f09 100644 --- a/deploy/crds/enterprise.splunk.com_monitoringconsoles_crd.yaml +++ b/deploy/crds/enterprise.splunk.com_monitoringconsoles_crd.yaml @@ -856,6 +856,43 @@ spec: licenseUrl: description: Full path or URL for a Splunk Enterprise license file type: string + monitoringConsoleRef: + description: MonitoringConsoleRef refers to a Splunk Enterprise monitoring + console managed by the operator within Kubernetes + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: 'If referring to a piece of an object instead of + an entire object, this string should contain a valid JSON/Go + field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within + a pod, this would take on a value like: "spec.containers{name}" + (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" + (container with index 2 in this pod). This syntax is chosen + only to have some well-defined way of referencing a part of + an object. TODO: this design is not final and this field is + subject to change in the future.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + type: string + resourceVersion: + description: 'Specific resourceVersion to which this reference + is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' + type: string + uid: + description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + type: string + type: object resources: description: resource requirements for the pod containers properties: diff --git a/deploy/crds/enterprise.splunk.com_searchheadclusters_crd.yaml b/deploy/crds/enterprise.splunk.com_searchheadclusters_crd.yaml index 7c7ef230b..e0c0657c4 100644 --- a/deploy/crds/enterprise.splunk.com_searchheadclusters_crd.yaml +++ b/deploy/crds/enterprise.splunk.com_searchheadclusters_crd.yaml @@ -874,6 +874,43 @@ spec: licenseUrl: description: Full path or URL for a Splunk Enterprise license file type: string + monitoringConsoleRef: + description: MonitoringConsoleRef refers to a Splunk Enterprise monitoring + console managed by the operator within Kubernetes + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: 'If referring to a piece of an object instead of + an entire object, this string should contain a valid JSON/Go + field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within + a pod, this would take on a value like: "spec.containers{name}" + (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" + (container with index 2 in this pod). This syntax is chosen + only to have some well-defined way of referencing a part of + an object. TODO: this design is not final and this field is + subject to change in the future.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + type: string + resourceVersion: + description: 'Specific resourceVersion to which this reference + is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' + type: string + uid: + description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + type: string + type: object replicas: description: Number of search head pods; a search head cluster will be created if > 1 diff --git a/deploy/crds/enterprise.splunk.com_standalones_crd.yaml b/deploy/crds/enterprise.splunk.com_standalones_crd.yaml index fc477e27b..99d792b89 100644 --- a/deploy/crds/enterprise.splunk.com_standalones_crd.yaml +++ b/deploy/crds/enterprise.splunk.com_standalones_crd.yaml @@ -869,6 +869,43 @@ spec: licenseUrl: description: Full path or URL for a Splunk Enterprise license file type: string + monitoringConsoleRef: + description: MonitoringConsoleRef refers to a Splunk Enterprise monitoring + console managed by the operator within Kubernetes + properties: + apiVersion: + description: API version of the referent. + type: string + fieldPath: + description: 'If referring to a piece of an object instead of + an entire object, this string should contain a valid JSON/Go + field access statement, such as desiredState.manifest.containers[2]. + For example, if the object reference is to a container within + a pod, this would take on a value like: "spec.containers{name}" + (where "name" refers to the name of the container that triggered + the event) or if no container name is specified "spec.containers[2]" + (container with index 2 in this pod). This syntax is chosen + only to have some well-defined way of referencing a part of + an object. TODO: this design is not final and this field is + subject to change in the future.' + type: string + kind: + description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names' + type: string + namespace: + description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/' + type: string + resourceVersion: + description: 'Specific resourceVersion to which this reference + is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency' + type: string + uid: + description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids' + type: string + type: object replicas: description: Number of standalone pods format: int32 diff --git a/pkg/apis/enterprise/v1/common_types.go b/pkg/apis/enterprise/v1/common_types.go index d6ad95fc1..09b9f24c8 100644 --- a/pkg/apis/enterprise/v1/common_types.go +++ b/pkg/apis/enterprise/v1/common_types.go @@ -67,6 +67,9 @@ type CommonSplunkSpec struct { // ClusterMasterRef refers to a Splunk Enterprise indexer cluster managed by the operator within Kubernetes ClusterMasterRef corev1.ObjectReference `json:"clusterMasterRef"` + // MonitoringConsoleRef refers to a Splunk Enterprise monitoring console managed by the operator within Kubernetes + MonitoringConsoleRef corev1.ObjectReference `json:"monitoringConsoleRef"` + // Mock to differentiate between UTs and actual reconcile Mock bool `json:"Mock"` diff --git a/pkg/apis/enterprise/v1/zz_generated.deepcopy.go b/pkg/apis/enterprise/v1/zz_generated.deepcopy.go index 59827775f..b4161ae31 100644 --- a/pkg/apis/enterprise/v1/zz_generated.deepcopy.go +++ b/pkg/apis/enterprise/v1/zz_generated.deepcopy.go @@ -161,6 +161,7 @@ func (in *CommonSplunkSpec) DeepCopyInto(out *CommonSplunkSpec) { } out.LicenseMasterRef = in.LicenseMasterRef out.ClusterMasterRef = in.ClusterMasterRef + out.MonitoringConsoleRef = in.MonitoringConsoleRef if in.ExtraEnv != nil { in, out := &in.ExtraEnv, &out.ExtraEnv *out = make([]corev1.EnvVar, len(*in)) diff --git a/pkg/controller/add_monitoringconsole.go b/pkg/controller/add_monitoringconsole.go index 22fdbcc50..ab1aac09a 100644 --- a/pkg/controller/add_monitoringconsole.go +++ b/pkg/controller/add_monitoringconsole.go @@ -49,7 +49,7 @@ func (ctrl MonitoringConsoleController) GetInstance() splcommon.MetaObject { // GetWatchTypes returns a list of types owned by the controller that it would like to receive watch events for func (ctrl MonitoringConsoleController) GetWatchTypes() []runtime.Object { - return []runtime.Object{&appsv1.StatefulSet{}, &corev1.Secret{}} + return []runtime.Object{&appsv1.StatefulSet{}, &corev1.Secret{}, &corev1.ConfigMap{}} } // Reconcile is used to perform an idempotent reconciliation of the custom resource managed by this controller diff --git a/pkg/splunk/enterprise/licensemaster.go b/pkg/splunk/enterprise/licensemaster.go index 116b73479..44921ec11 100644 --- a/pkg/splunk/enterprise/licensemaster.go +++ b/pkg/splunk/enterprise/licensemaster.go @@ -58,6 +58,12 @@ func ApplyLicenseMaster(client splcommon.ControllerClient, cr *enterprisev1.Lice // check if deletion has been requested if cr.ObjectMeta.DeletionTimestamp != nil { + if cr.Spec.MonitoringConsoleRef.Name != "" { + _, err = ApplyMonitoringConsoleEnvConfigMap(client, cr.GetNamespace(), cr.GetName(), cr.Spec.MonitoringConsoleRef.Name, getLicenseMasterURL(cr, &cr.Spec.CommonSplunkSpec), false) + if err != nil { + return result, err + } + } DeleteOwnerReferencesForResources(client, cr, nil) terminating, err := splctrl.CheckForDeletion(cr, client) if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after @@ -94,6 +100,12 @@ func ApplyLicenseMaster(client splcommon.ControllerClient, cr *enterprisev1.Lice if err != nil { scopedLog.Error(err, "Error in deleting automated monitoring console resource") } + if cr.Spec.MonitoringConsoleRef.Name != "" { + _, err = ApplyMonitoringConsoleEnvConfigMap(client, cr.GetNamespace(), cr.GetName(), cr.Spec.MonitoringConsoleRef.Name, getLicenseMasterURL(cr, &cr.Spec.CommonSplunkSpec), true) + if err != nil { + return result, err + } + } result.Requeue = false } return result, nil diff --git a/pkg/splunk/enterprise/monitoringconsole.go b/pkg/splunk/enterprise/monitoringconsole.go index c2bc0992f..72c1cd8ac 100644 --- a/pkg/splunk/enterprise/monitoringconsole.go +++ b/pkg/splunk/enterprise/monitoringconsole.go @@ -145,12 +145,12 @@ func validateMonitoringConsoleSpec(spec *enterprisev1.MonitoringConsoleSpec) err } //ApplyMonitoringConsoleEnvConfigMap creates or updates a Kubernetes ConfigMap for extra env for monitoring console pod -func ApplyMonitoringConsoleEnvConfigMap(client splcommon.ControllerClient, namespace string, crName string, newURLs []corev1.EnvVar, addNewURLs bool) (*corev1.ConfigMap, error) { +func ApplyMonitoringConsoleEnvConfigMap(client splcommon.ControllerClient, namespace string, crName string, monitoringConsoleRef string, newURLs []corev1.EnvVar, addNewURLs bool) (*corev1.ConfigMap, error) { var current corev1.ConfigMap current.Data = make(map[string]string) - configMap := GetSplunkMonitoringconsoleConfigMapName(namespace, SplunkMonitoringConsole) + configMap := GetSplunkMonitoringconsoleConfigMapName(monitoringConsoleRef, SplunkMonitoringConsole) namespacedName := types.NamespacedName{Namespace: namespace, Name: configMap} err := client.Get(context.TODO(), namespacedName, ¤t) diff --git a/pkg/splunk/enterprise/monitoringconsole_test.go b/pkg/splunk/enterprise/monitoringconsole_test.go index aebfff4ac..891d209b5 100644 --- a/pkg/splunk/enterprise/monitoringconsole_test.go +++ b/pkg/splunk/enterprise/monitoringconsole_test.go @@ -90,8 +90,9 @@ func TestApplyMonitoringConsoleEnvConfigMap(t *testing.T) { } newURLsAdded := true + monitoringConsoleRef := "test" reconcile := func(c *spltest.MockClient, cr interface{}) error { - _, err := ApplyMonitoringConsoleEnvConfigMap(c, "test", "test", env, newURLsAdded) + _, err := ApplyMonitoringConsoleEnvConfigMap(c, "test", "test", monitoringConsoleRef, env, newURLsAdded) return err } diff --git a/pkg/splunk/enterprise/searchheadcluster.go b/pkg/splunk/enterprise/searchheadcluster.go index c90101113..ef46fdf98 100644 --- a/pkg/splunk/enterprise/searchheadcluster.go +++ b/pkg/splunk/enterprise/searchheadcluster.go @@ -80,6 +80,12 @@ func ApplySearchHeadCluster(client splcommon.ControllerClient, cr *enterprisev1. // check if deletion has been requested if cr.ObjectMeta.DeletionTimestamp != nil { + if cr.Spec.MonitoringConsoleRef.Name != "" { + _, err = ApplyMonitoringConsoleEnvConfigMap(client, cr.GetNamespace(), cr.GetName(), cr.Spec.MonitoringConsoleRef.Name, getSearchHeadEnv(cr), false) + if err != nil { + return result, err + } + } DeleteOwnerReferencesForResources(client, cr, nil) terminating, err := splctrl.CheckForDeletion(cr, client) if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after @@ -141,6 +147,12 @@ func ApplySearchHeadCluster(client splcommon.ControllerClient, cr *enterprisev1. if err != nil { scopedLog.Error(err, "Error in deleting automated monitoring console resource") } + if cr.Spec.MonitoringConsoleRef.Name != "" { + _, err = ApplyMonitoringConsoleEnvConfigMap(client, cr.GetNamespace(), cr.GetName(), cr.Spec.MonitoringConsoleRef.Name, getSearchHeadEnv(cr), true) + if err != nil { + return result, err + } + } result.Requeue = false // Reset secrets related status structs diff --git a/pkg/splunk/enterprise/standalone.go b/pkg/splunk/enterprise/standalone.go index 01f764a04..22ac4b4a4 100644 --- a/pkg/splunk/enterprise/standalone.go +++ b/pkg/splunk/enterprise/standalone.go @@ -82,6 +82,12 @@ func ApplyStandalone(client splcommon.ControllerClient, cr *enterprisev1.Standal // check if deletion has been requested if cr.ObjectMeta.DeletionTimestamp != nil { + if cr.Spec.MonitoringConsoleRef.Name != "" { + _, err = ApplyMonitoringConsoleEnvConfigMap(client, cr.GetNamespace(), cr.GetName(), cr.Spec.MonitoringConsoleRef.Name, getStandaloneExtraEnv(cr, cr.Spec.Replicas), false) + if err != nil { + return result, err + } + } DeleteOwnerReferencesForResources(client, cr, &cr.Spec.SmartStore) terminating, err := splctrl.CheckForDeletion(cr, client) if terminating && err != nil { // don't bother if no error, since it will just be removed immmediately after @@ -126,6 +132,12 @@ func ApplyStandalone(client splcommon.ControllerClient, cr *enterprisev1.Standal if err != nil { scopedLog.Error(err, "Error in deleting automated monitoring console resource") } + if cr.Spec.MonitoringConsoleRef.Name != "" { + _, err = ApplyMonitoringConsoleEnvConfigMap(client, cr.GetNamespace(), cr.GetName(), cr.Spec.MonitoringConsoleRef.Name, getStandaloneExtraEnv(cr, cr.Spec.Replicas), true) + if err != nil { + return result, err + } + } result.Requeue = false } return result, nil