Skip to content

Commit

Permalink
fix return and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
SrinivasAtmakuri committed Sep 18, 2023
1 parent 4edfd77 commit 66c6f92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
21 changes: 16 additions & 5 deletions pkg/frontend/admin_openshiftcluster_etcdcertificaterenew.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (e *etcdrenew) fetchEtcdCurrentRevision(ctx context.Context) error {
func (e *etcdrenew) backupEtcdSecrets(ctx context.Context) error {
e.log.Infoln("backing up etcd secrets now")
for _, secretname := range e.secretNames {
return retry.OnError(wait.Backoff{
err := retry.OnError(wait.Backoff{
Steps: 10,
Duration: 2 * time.Second,
}, func(err error) bool {
Expand Down Expand Up @@ -340,6 +340,9 @@ func (e *etcdrenew) backupEtcdSecrets(ctx context.Context) error {
e.backupSecrets[secretname] = cert
return nil
})
if err != nil {
return err
}
}

e.log.Infoln("backing up etcd secrets done")
Expand All @@ -351,7 +354,7 @@ func (e *etcdrenew) backupEtcdSecrets(ctx context.Context) error {
func (e *etcdrenew) deleteEtcdSecrets(ctx context.Context) error {
e.log.Infoln("deleting etcd secrets now")
for _, secretname := range e.secretNames {
return retry.OnError(wait.Backoff{
err := retry.OnError(wait.Backoff{
Steps: 10,
Duration: 2 * time.Second,
}, func(err error) bool {
Expand All @@ -365,6 +368,9 @@ func (e *etcdrenew) deleteEtcdSecrets(ctx context.Context) error {
e.log.Infof("Secret deleted %s", secretname)
return nil
})
if err != nil {
return err
}
}

return nil
Expand All @@ -375,12 +381,14 @@ func (e *etcdrenew) isEtcdRevised(ctx context.Context) (bool, error) {
isAtRevision := true
rawEtcd, err := e.k.KubeGet(ctx, "etcd.operator.openshift.io", "", "cluster")
if err != nil {
return false, api.NewCloudError(http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", err.Error())
e.log.Warnf(err.Error())
return false, nil
}
etcd := &operatorv1.Etcd{}
err = codec.NewDecoderBytes(rawEtcd, &codec.JsonHandle{}).Decode(etcd)
if err != nil {
return false, api.NewCloudError(http.StatusInternalServerError, api.CloudErrorCodeInternalServerError, "", fmt.Sprintf("failed to decode etcd object, %s", err.Error()))
e.log.Warnf(err.Error())
return false, nil
}

// no new revision is observed.
Expand All @@ -403,7 +411,7 @@ func (e *etcdrenew) isEtcdRevised(ctx context.Context) (bool, error) {
func (e *etcdrenew) recoverEtcdSecrets(ctx context.Context) error {
e.log.Infoln("recovering etcd secrets now")
for secretname, data := range e.backupSecrets {
return retry.OnError(wait.Backoff{
err := retry.OnError(wait.Backoff{
Steps: 10,
Duration: 2 * time.Second,
}, func(err error) bool {
Expand All @@ -422,6 +430,9 @@ func (e *etcdrenew) recoverEtcdSecrets(ctx context.Context) error {
}
return nil
})
if err != nil {
return err
}
}
e.log.Infoln("recovered etcd secrets")

Expand Down
20 changes: 10 additions & 10 deletions pkg/frontend/admin_openshiftcluster_etcdcertificaterenew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ func TestAdminEtcdCertificateRenew(t *testing.T) {
KubeGet(gomock.Any(), "ClusterVersion.config.openshift.io", "", "version").MaxTimes(1).
Return(encodeClusterVersion(t, tt.version), nil)
k.EXPECT().
KubeGet(gomock.Any(), "etcd.operator.openshift.io", "", "cluster").AnyTimes().
KubeGet(gomock.Any(), "etcd.operator.openshift.io", "", "cluster").MinTimes(1).
Return(encodeEtcdOperatorController(t, tt.etcdoperator), nil)
k.EXPECT().
KubeGet(gomock.Any(), "ClusterOperator.config.openshift.io", "", "etcd").AnyTimes().
KubeGet(gomock.Any(), "ClusterOperator.config.openshift.io", "", "etcd").MinTimes(1).
Return(encodeEtcdOperator(t, tt.etcdCO), nil)
k.EXPECT().
KubeGet(gomock.Any(), "Secret", namespaceEtcds, gomock.Any()).AnyTimes().
KubeGet(gomock.Any(), "Secret", namespaceEtcds, gomock.Any()).MinTimes(1).
Return(CreateCertSecret(t, tt.notBefore, tt.notAfter), nil)
},
wantStatusCode: http.StatusInternalServerError,
Expand Down Expand Up @@ -262,13 +262,13 @@ func TestAdminEtcdCertificateRenew(t *testing.T) {
KubeGet(gomock.Any(), "ClusterVersion.config.openshift.io", "", "version").MaxTimes(1).
Return(encodeClusterVersion(t, tt.version), nil)
k.EXPECT().
KubeGet(gomock.Any(), "etcd.operator.openshift.io", "", "cluster").AnyTimes().
KubeGet(gomock.Any(), "etcd.operator.openshift.io", "", "cluster").MinTimes(1).
Return(encodeEtcdOperatorController(t, tt.etcdoperator), nil)
k.EXPECT().
KubeGet(gomock.Any(), "ClusterOperator.config.openshift.io", "", "etcd").AnyTimes().
KubeGet(gomock.Any(), "ClusterOperator.config.openshift.io", "", "etcd").MinTimes(1).
Return(encodeEtcdOperator(t, tt.etcdCO), nil)
k.EXPECT().
KubeGet(gomock.Any(), "Secret", namespaceEtcds, gomock.Any()).AnyTimes().
KubeGet(gomock.Any(), "Secret", namespaceEtcds, gomock.Any()).MinTimes(1).
Return(CreateCertSecret(t, tt.notBefore, tt.notAfter), nil)
},
wantStatusCode: http.StatusInternalServerError,
Expand Down Expand Up @@ -349,16 +349,16 @@ func TestAdminEtcdCertificateRenew(t *testing.T) {
KubeGet(gomock.Any(), "etcd.operator.openshift.io", "", "cluster").MaxTimes(2).
Return(encodeEtcdOperatorController(t, tt.etcdoperator), nil)
k.EXPECT().
KubeGet(gomock.Any(), "ClusterOperator.config.openshift.io", "", "etcd").AnyTimes().
KubeGet(gomock.Any(), "ClusterOperator.config.openshift.io", "", "etcd").MinTimes(1).
Return(encodeEtcdOperator(t, tt.etcdCO), nil)
k.EXPECT().
KubeGet(gomock.Any(), "Secret", namespaceEtcds, gomock.Any()).AnyTimes().
KubeGet(gomock.Any(), "Secret", namespaceEtcds, gomock.Any()).MinTimes(9).
Return(CreateCertSecret(t, tt.notBefore, tt.notAfter), nil)
d := k.EXPECT().
KubeDelete(gomock.Any(), "Secret", namespaceEtcds, gomock.Any(), false, nil).MaxTimes(9).
KubeDelete(gomock.Any(), "Secret", namespaceEtcds, gomock.Any(), false, nil).MinTimes(9).
Return(nil)
k.EXPECT().
KubeGet(gomock.Any(), "etcd.operator.openshift.io", "", "cluster").AnyTimes().After(d).
KubeGet(gomock.Any(), "etcd.operator.openshift.io", "", "cluster").MinTimes(1).After(d).
Return(encodeEtcdOperatorController(t, tt.etcdoperatorRevisied), nil)
},
wantStatusCode: http.StatusOK,
Expand Down

0 comments on commit 66c6f92

Please sign in to comment.