Skip to content

Commit

Permalink
Update operator information (#1139)
Browse files Browse the repository at this point in the history
- Remove the operator namespace in the operator information because it may be seen as private
- Rename the uuid field in operator_uuid
- Add a boolean field for the use of a custom operator namespace
- Add operator roles
  • Loading branch information
thbkrkr authored Jul 2, 2019
1 parent ccf1a6d commit 1c59ed0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions operators/cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
33 changes: 22 additions & 11 deletions operators/pkg/about/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions operators/pkg/about/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

0 comments on commit 1c59ed0

Please sign in to comment.