Skip to content

Commit

Permalink
openshift: Ensure new webhook secret (#1268)
Browse files Browse the repository at this point in the history
The non openshift secret is not compatible with openshift generated
version, this change a different one so they don't collide and also
remove the old one.

Signed-off-by: Enrique Llorente <[email protected]>
  • Loading branch information
qinqon authored Oct 1, 2024
1 parent 6d8c399 commit 8506e7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 12 additions & 1 deletion controllers/operator/nmstate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,20 @@ func (r *NMStateReconciler) cleanupObsoleteResources(ctx context.Context) error
Name: os.Getenv("HANDLER_PREFIX") + "nmstate-cert-manager",
},
})
if !apierrors.IsNotFound(err) {
if err != nil && apierrors.IsNotFound(err) {
return fmt.Errorf("failed deleting obsolete cert-manager deployment at openshift: %w", err)
}

// Remove the non openshift secret
err = r.Client.Delete(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: os.Getenv("HANDLER_NAMESPACE"),
Name: os.Getenv("HANDLER_PREFIX") + "nmstate-webhook",
},
})
if err != nil && apierrors.IsNotFound(err) {
return fmt.Errorf("failed deleting old webhook secret at openshift: %w", err)
}
}
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion deploy/handler/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ spec:
volumes:
- name: tls-key-pair
secret:
{{- if not .IsOpenShift }}
secretName: {{template "handlerPrefix" .}}nmstate-webhook
{{- else }}
secretName: {{template "handlerPrefix" .}}openshift-nmstate-webhook
{{- end }}
{{- if not .IsOpenShift }}
---
apiVersion: apps/v1
Expand Down Expand Up @@ -391,7 +395,7 @@ metadata:
name: {{template "handlerPrefix" .}}nmstate-webhook
namespace: {{ .HandlerNamespace }}
annotations:
service.beta.openshift.io/serving-cert-secret-name: {{template "handlerPrefix" .}}nmstate-webhook
service.beta.openshift.io/serving-cert-secret-name: {{template "handlerPrefix" .}}openshift-nmstate-webhook
labels:
app: kubernetes-nmstate
spec:
Expand Down

0 comments on commit 8506e7b

Please sign in to comment.