Skip to content

Commit

Permalink
Code review comments have been addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
lbossis committed Nov 15, 2024
1 parent ade1f7a commit f2991ab
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 32 deletions.
5 changes: 5 additions & 0 deletions pkg/operator/controllers/pullsecret/pullsecret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}

err = r.Client.Update(ctx, instance)
if err == nil {
r.ClearConditions(ctx)
} else {
r.SetDegraded(ctx, err)
}
return reconcile.Result{}, err
}

Expand Down
94 changes: 62 additions & 32 deletions pkg/operator/controllers/pullsecret/pullsecret_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
"testing"

operatorv1 "github.com/openshift/api/operator/v1"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
Expand All @@ -22,6 +23,7 @@ import (
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/util/cmp"
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
utilconditions "github.com/Azure/ARO-RP/test/util/conditions"
utilerror "github.com/Azure/ARO-RP/test/util/error"
)

Expand All @@ -37,14 +39,21 @@ func TestPullSecretReconciler(t *testing.T) {
},
}

defaultAvailable := utilconditions.ControllerDefaultAvailable(ControllerName)
defaultProgressing := utilconditions.ControllerDefaultProgressing(ControllerName)
defaultDegraded := utilconditions.ControllerDefaultDegraded(ControllerName)
defaultConditions := []operatorv1.OperatorCondition{defaultAvailable, defaultProgressing, defaultDegraded}

tests := []struct {
name string
request ctrl.Request
secrets []client.Object
instance *arov1alpha1.Cluster
wantKeys []string
wantErr bool
want string
name string
request ctrl.Request
secrets []client.Object
instance *arov1alpha1.Cluster
wantKeys []string
wantErr bool
want string
wantErrMsg string
wantConditions []operatorv1.OperatorCondition
}{
{
name: "deleted pull secret",
Expand All @@ -58,9 +67,11 @@ func TestPullSecretReconciler(t *testing.T) {
Data: map[string][]byte{corev1.DockerConfigJsonKey: []byte(`{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`)},
},
},
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
wantErrMsg: "",
wantConditions: defaultConditions,
},
{
name: "missing arosvc pull secret",
Expand All @@ -81,9 +92,11 @@ func TestPullSecretReconciler(t *testing.T) {
Data: map[string][]byte{corev1.DockerConfigJsonKey: []byte(`{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`)},
},
},
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
wantErrMsg: "",
wantConditions: defaultConditions,
},
{
name: "modified arosvc pull secret",
Expand All @@ -107,9 +120,11 @@ func TestPullSecretReconciler(t *testing.T) {
Data: map[string][]byte{corev1.DockerConfigJsonKey: []byte(`{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`)},
},
},
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
wantErrMsg: "",
wantConditions: defaultConditions,
},
{
name: "unparseable secret",
Expand All @@ -131,9 +146,11 @@ func TestPullSecretReconciler(t *testing.T) {
Data: map[string][]byte{corev1.DockerConfigJsonKey: []byte(`{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`)},
},
},
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
wantErrMsg: "",
wantConditions: defaultConditions,
},
{
name: "wrong secret type",
Expand All @@ -154,9 +171,11 @@ func TestPullSecretReconciler(t *testing.T) {
Data: map[string][]byte{corev1.DockerConfigJsonKey: []byte(`{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`)},
},
},
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
wantErrMsg: "",
wantConditions: defaultConditions,
},
{
name: "no change",
Expand All @@ -178,9 +197,11 @@ func TestPullSecretReconciler(t *testing.T) {
Data: map[string][]byte{corev1.DockerConfigJsonKey: []byte(`{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`)},
},
},
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
wantErrMsg: "",
wantConditions: defaultConditions,
},
{
name: "valid RH keys present",
Expand All @@ -206,9 +227,11 @@ func TestPullSecretReconciler(t *testing.T) {
},
},
},
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="},"registry.redhat.io":{"auth":"ZnJlZDplbnRlcg=="},"cloud.openshift.com":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: []string{"registry.redhat.io", "cloud.openshift.com"},
instance: baseCluster,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="},"registry.redhat.io":{"auth":"ZnJlZDplbnRlcg=="},"cloud.openshift.com":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: []string{"registry.redhat.io", "cloud.openshift.com"},
wantErrMsg: "",
wantConditions: defaultConditions,
},
{
name: "management disabled, valid RH key present",
Expand Down Expand Up @@ -244,8 +267,10 @@ func TestPullSecretReconciler(t *testing.T) {
},
},
},
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="},"registry.redhat.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: []string{"registry.redhat.io"},
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="},"registry.redhat.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: []string{"registry.redhat.io"},
wantErrMsg: "",
wantConditions: defaultConditions,
},
{
name: "management disabled, valid RH key missing",
Expand Down Expand Up @@ -277,8 +302,10 @@ func TestPullSecretReconciler(t *testing.T) {
},
},
},
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
want: `{"auths":{"arosvc.azurecr.io":{"auth":"ZnJlZDplbnRlcg=="}}}`,
wantKeys: nil,
wantErrMsg: "",
wantConditions: defaultConditions,
},
}
for _, tt := range tests {
Expand All @@ -301,6 +328,9 @@ func TestPullSecretReconciler(t *testing.T) {
return
}

utilerror.AssertErrorMessage(t, err, tt.wantErrMsg)
utilconditions.AssertControllerConditions(t, ctx, clientFake, tt.wantConditions)

s := &corev1.Secret{}
assert.NotNil(t, s)
err = r.Client.Get(ctx, types.NamespacedName{Namespace: "openshift-config", Name: "pull-secret"}, s)
Expand Down

0 comments on commit f2991ab

Please sign in to comment.