Skip to content
Open
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
6 changes: 3 additions & 3 deletions cmd/kubernetes/operator/kodata/webhook/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ spec:
replicas: 1
selector:
matchLabels:
name: tekton-operator
name: tekton-operator-proxy-webhook
template:
metadata:
labels:
name: tekton-operator
name: tekton-operator-proxy-webhook
Comment thread
bowling233 marked this conversation as resolved.
app: tekton-operator
spec:
serviceAccountName: tekton-operators-proxy-webhook
Expand Down Expand Up @@ -152,7 +152,7 @@ spec:
port: 443
targetPort: 8443
selector:
name: tekton-operator
name: tekton-operator-proxy-webhook

---

Expand Down
6 changes: 3 additions & 3 deletions cmd/openshift/operator/kodata/webhook/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ spec:
replicas: 1
selector:
matchLabels:
name: tekton-operator
name: tekton-operator-proxy-webhook
template:
metadata:
labels:
name: tekton-operator
name: tekton-operator-proxy-webhook
Comment thread
bowling233 marked this conversation as resolved.
app: tekton-operator
spec:
securityContext:
Expand Down Expand Up @@ -160,7 +160,7 @@ spec:
port: 443
targetPort: 8443
selector:
name: tekton-operator
name: tekton-operator-proxy-webhook

---

Expand Down
31 changes: 31 additions & 0 deletions pkg/reconciler/kubernetes/tektoninstallerset/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -528,6 +529,18 @@ func (i *installer) ensureResource(ctx context.Context, expected *unstructured.U
"expectedHash", expectedHashValue,
)

if selectorChanged, err := deploymentSelectorChanged(expected, existing); err != nil {
loggerWithContext.Errorw("failed to compare deployment selectors", "error", err)
return err
} else if selectorChanged {
loggerWithContext.Infow("deployment selector changed, deleting resource before recreate")
if err := i.mfClient.Delete(existing); err != nil {
loggerWithContext.Errorw("failed to delete deployment with changed selector", "error", err)
return v1alpha1.RECONCILE_AGAIN_ERR
}
return v1alpha1.RECONCILE_AGAIN_ERR
}

err = i.copyResourceFields(expected, existing, reconcileFields...)
if err != nil {
loggerWithContext.Errorw("failed to copy resource fields", "error", err)
Expand All @@ -547,6 +560,24 @@ func (i *installer) ensureResource(ctx context.Context, expected *unstructured.U
return nil
}

func deploymentSelectorChanged(expected, existing *unstructured.Unstructured) (bool, error) {
if expected.GetKind() != "Deployment" {
return false, nil
}

expectedDeployment := &appsv1.Deployment{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(expected.Object, expectedDeployment); err != nil {
return false, err
}

existingDeployment := &appsv1.Deployment{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(existing.Object, existingDeployment); err != nil {
return false, err
}

return !equality.Semantic.DeepEqual(expectedDeployment.Spec.Selector, existingDeployment.Spec.Selector), nil
}

func (i *installer) removeExtraKeyInMap(src, dst map[string]string) map[string]string {
newMap := map[string]string{}
if len(src) == 0 {
Expand Down