diff --git a/operators/cmd/manager/main.go b/operators/cmd/manager/main.go index af3c6d5117..c9f8995711 100644 --- a/operators/cmd/manager/main.go +++ b/operators/cmd/manager/main.go @@ -248,7 +248,7 @@ func execute() { os.Exit(1) } - operatorInfo, err := about.GetOperatorInfo(clientset, operatorNamespace) + operatorInfo, err := about.GetOperatorInfo(clientset, operatorNamespace, roles) if err != nil { log.Error(err, "unable to get operator info") os.Exit(1) @@ -279,8 +279,8 @@ func execute() { os.Exit(1) } - log.Info("Starting the manager", "uuid", operatorInfo.UUID, - "namespace", operatorInfo.Namespace, "version", operatorInfo.BuildInfo.Version, + log.Info("Starting the manager", "uuid", operatorInfo.OperatorUUID, + "namespace", operatorNamespace, "version", operatorInfo.BuildInfo.Version, "build_hash", operatorInfo.BuildInfo.Hash, "build_date", operatorInfo.BuildInfo.Date, "build_snapshot", operatorInfo.BuildInfo.Snapshot) if err := mgr.Start(signals.SetupSignalHandler()); err != nil { diff --git a/operators/pkg/about/info.go b/operators/pkg/about/info.go index af52c0dc4b..c7b3eff582 100644 --- a/operators/pkg/about/info.go +++ b/operators/pkg/about/info.go @@ -21,12 +21,15 @@ const ( UUIDCfgMapKey = "uuid" ) +var defaultOperatorNamespaces = []string{"elastic-system", "elastic-namespace-operators"} + // OperatorInfo contains information about the operator. type OperatorInfo struct { - UUID types.UID `json:"uuid"` - Namespace string `json:"namespace"` - Distribution string `json:"distribution"` - BuildInfo BuildInfo `json:"build"` + OperatorUUID types.UID `json:"operator_uuid"` + OperatorRoles []string `json:"operator_roles"` + CustomOperatorNamespace bool `json:"custom_operator_namespace"` + Distribution string `json:"distribution"` + BuildInfo BuildInfo `json:"build"` } // BuildInfo contains build metadata information. @@ -39,16 +42,16 @@ type BuildInfo struct { // IsDefined returns true if the info's default values have been replaced. func (i OperatorInfo) IsDefined() bool { - return i.UUID != "" && - i.Namespace != "" && + return i.OperatorUUID != "" && i.Distribution != "" && i.BuildInfo.Version != "0.0.0" && i.BuildInfo.Hash != "00000000" && i.BuildInfo.Date != "1970-01-01T00:00:00Z" } -// GetOperatorInfo returns an OperatorInfo given an operator client, a Kubernetes client config and an operator namespace. -func GetOperatorInfo(clientset kubernetes.Interface, operatorNs string) (OperatorInfo, error) { +// GetOperatorInfo returns an OperatorInfo given an operator client, a Kubernetes client config, an operator namespace +// and operator roles. +func GetOperatorInfo(clientset kubernetes.Interface, operatorNs string, operatorRoles []string) (OperatorInfo, error) { operatorUUID, err := getOperatorUUID(clientset, operatorNs) if err != nil { return OperatorInfo{}, err @@ -59,10 +62,18 @@ func GetOperatorInfo(clientset kubernetes.Interface, operatorNs string) (Operato return OperatorInfo{}, err } + customOperatorNs := true + for _, ns := range defaultOperatorNamespaces { + if operatorNs == ns { + customOperatorNs = false + } + } + return OperatorInfo{ - UUID: operatorUUID, - Namespace: operatorNs, - Distribution: distribution, + OperatorUUID: operatorUUID, + OperatorRoles: operatorRoles, + CustomOperatorNamespace: customOperatorNs, + Distribution: distribution, BuildInfo: BuildInfo{ version, buildHash, diff --git a/operators/pkg/about/info_test.go b/operators/pkg/about/info_test.go index 2f7dc06180..cd8ffe95e8 100644 --- a/operators/pkg/about/info_test.go +++ b/operators/pkg/about/info_test.go @@ -68,19 +68,19 @@ func TestGetOperatorInfo(t *testing.T) { fakeClientset := k8sfake.NewSimpleClientset(test.initObjs...) // retrieve operator info a first time - operatorInfo, err := GetOperatorInfo(fakeClientset, fakeOperatorNs) + operatorInfo, err := GetOperatorInfo(fakeClientset, fakeOperatorNs, []string{"all"}) require.NoError(t, err) // the operator uuid should be defined - uuid := operatorInfo.UUID + uuid := operatorInfo.OperatorUUID test.assert(uuid) // retrieve operator info a second time - operatorInfo, err = GetOperatorInfo(fakeClientset, fakeOperatorNs) + operatorInfo, err = GetOperatorInfo(fakeClientset, fakeOperatorNs, []string{"all"}) require.NoError(t, err) // the operator uuid should be the same than the first time - assert.Equal(t, uuid, operatorInfo.UUID) + assert.Equal(t, uuid, operatorInfo.OperatorUUID) }) } }