Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROX-16205: Add Operator Version label to Centrals #909

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fleetshard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {
glog.Infof("ClusterID: %s", config.ClusterID)
glog.Infof("RuntimePollPeriod: %s", config.RuntimePollPeriod.String())
glog.Infof("AuthType: %s", config.AuthType)
glog.Infof("FeatureFlagUpgradeOperatorEnabled: %t", config.FeatureFlagUpgradeOperatorEnabled)

glog.Infof("ManagedDB.Enabled: %t", config.ManagedDB.Enabled)
glog.Infof("ManagedDB.SecurityGroup: %s", config.ManagedDB.SecurityGroup)
Expand Down
27 changes: 20 additions & 7 deletions fleetshard/pkg/central/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const (
instanceTypeLabelKey = "rhacs.redhat.com/instance-type"
orgIDLabelKey = "rhacs.redhat.com/org-id"
tenantIDLabelKey = "rhacs.redhat.com/tenant"
operatorVersionKey = "stackrox.io/operator-version"
defaultOperatorVersion = "rhacs-operator.v3.74.0"

dbUserTypeAnnotation = "platform.stackrox.io/user-type"
dbUserTypeMaster = "master"
Expand All @@ -57,13 +59,14 @@ const (

// CentralReconcilerOptions are the static options for creating a reconciler.
type CentralReconcilerOptions struct {
UseRoutes bool
WantsAuthProvider bool
EgressProxyImage string
ManagedDBEnabled bool
Telemetry config.Telemetry
ClusterName string
Environment string
UseRoutes bool
WantsAuthProvider bool
EgressProxyImage string
ManagedDBEnabled bool
Telemetry config.Telemetry
ClusterName string
Environment string
FeatureFlagUpgradeOperatorEnabled bool
}

// CentralReconciler is a reconciler tied to a one Central instance. It installs, updates and deletes Central instances
Expand All @@ -87,6 +90,8 @@ type CentralReconciler struct {
managedDBProvisioningClient cloudprovider.DBClient
managedDBInitFunc postgres.CentralDBInitFunc

featureFlagUpgradeOperatorEnabled bool

resourcesChart *chart.Chart
}

Expand Down Expand Up @@ -200,6 +205,12 @@ func (r *CentralReconciler) Reconcile(ctx context.Context, remoteCentral private
},
}

if r.featureFlagUpgradeOperatorEnabled {
labels := central.ObjectMeta.Labels
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a nil check ?

e.g.
if labels == nil { labels = map[string]string{} } 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because it is set hardcoded above and not returned.
Even as a return value from the k8s API it is guaranteed to be set, except if nil is returned.

labels[operatorVersionKey] = defaultOperatorVersion
central.ObjectMeta.Labels = labels
}

// Check whether auth provider is actually created and this reconciler just is not aware of that.
if r.wantsAuthProvider && !r.hasAuthProvider {
exists, err := existsRHSSOAuthProvider(ctx, remoteCentral, r.client)
Expand Down Expand Up @@ -954,6 +965,8 @@ func NewCentralReconciler(k8sClient ctrlClient.Client, central private.ManagedCe
clusterName: opts.ClusterName,
environment: opts.Environment,

featureFlagUpgradeOperatorEnabled: opts.FeatureFlagUpgradeOperatorEnabled,

managedDBEnabled: opts.ManagedDBEnabled,
managedDBProvisioningClient: managedDBProvisioningClient,
managedDBInitFunc: managedDBInitFunc,
Expand Down
21 changes: 21 additions & 0 deletions fleetshard/pkg/central/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ func TestReconcileCreateWithManagedDB(t *testing.T) {
assert.NotEmpty(t, password)
}

func TestReconcileCreateWithLabelOperatorVersion(t *testing.T) {
fakeClient := testutils.NewFakeClientBuilder(t).Build()

r := NewCentralReconciler(fakeClient, private.ManagedCentral{}, nil, centralDBInitFunc,
CentralReconcilerOptions{
UseRoutes: true,
FeatureFlagUpgradeOperatorEnabled: true,
})

status, err := r.Reconcile(context.TODO(), simpleManagedCentral)
require.NoError(t, err)
readyCondition, ok := conditionForType(status.Conditions, conditionTypeReady)
require.True(t, ok)
assert.Equal(t, "True", readyCondition.Status, "Ready condition not found in conditions", status.Conditions)

central := &v1alpha1.Central{}
err = fakeClient.Get(context.TODO(), client.ObjectKey{Name: centralName, Namespace: centralNamespace}, central)
require.NoError(t, err)
assert.Equal(t, defaultOperatorVersion, central.ObjectMeta.Labels[operatorVersionKey])
}

func TestReconcileCreateWithManagedDBNoCredentials(t *testing.T) {
fakeClient := testutils.NewFakeClientBuilder(t).Build()

Expand Down
15 changes: 8 additions & 7 deletions fleetshard/pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ func (r *Runtime) Start() error {
routesAvailable := r.routesAvailable()

reconcilerOpts := centralReconciler.CentralReconcilerOptions{
UseRoutes: routesAvailable,
WantsAuthProvider: r.config.CreateAuthProvider,
EgressProxyImage: r.config.EgressProxyImage,
ManagedDBEnabled: r.config.ManagedDB.Enabled,
Telemetry: r.config.Telemetry,
ClusterName: r.config.ClusterName,
Environment: r.config.Environment,
UseRoutes: routesAvailable,
WantsAuthProvider: r.config.CreateAuthProvider,
EgressProxyImage: r.config.EgressProxyImage,
ManagedDBEnabled: r.config.ManagedDB.Enabled,
Telemetry: r.config.Telemetry,
ClusterName: r.config.ClusterName,
Environment: r.config.Environment,
FeatureFlagUpgradeOperatorEnabled: r.config.FeatureFlagUpgradeOperatorEnabled,
}

if r.config.FeatureFlagUpgradeOperatorEnabled {
Expand Down