Skip to content

Commit

Permalink
fix operator webhook upgrade issue
Browse files Browse the repository at this point in the history
Signed-off-by: Jeeva Kandasamy <[email protected]>
  • Loading branch information
jkandasa committed Nov 28, 2023
1 parent 4504813 commit 2f0bf7c
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions pkg/webhook/webhook_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,28 @@ import (
"knative.dev/pkg/logging"
)

const WEBHOOK_INSTALLERSET_LABEL = "validating-defaulting-webhooks.operator.tekton.dev"
const POD_NAMESPACE_ENV_KEY = "SYSTEM_NAMESPACE"
const (
// deprecated label, used in old versions
// keeps this reference to remove the existing webhook installersets
DEPRECATED_WEBHOOK_INSTALLERSET_LABEL = "validating-defaulting-webhooks.operator.tekton.dev"

// primary label values to track webhook installersets
labelCreatedByValue = "operator-webhook-init"
labelInstallerSetType = "operatorValidatingDefaultingWebhook"

POD_NAMESPACE_ENV_KEY = "SYSTEM_NAMESPACE"
)

var (
ErrNamespaceEnvNotSet = fmt.Errorf("namespace environment key %q not set", POD_NAMESPACE_ENV_KEY)

// primary labelSelector to list available webhooks installersets
primaryLabelSelector = metav1.LabelSelector{
MatchLabels: map[string]string{
v1alpha1.CreatedByKey: labelCreatedByValue,
v1alpha1.InstallerSetType: labelInstallerSetType,
},
}
)

func CreateWebhookResources(ctx context.Context) {
Expand Down Expand Up @@ -80,11 +97,25 @@ func manifestTransform(m *mf.Manifest) (*mf.Manifest, error) {
}

func deleteExistingInstallerSets(ctx context.Context, oc clientset.Interface) error {
// deleting the existing webhook installersets
// deleting the existing deprecated webhook installersets
err := oc.OperatorV1alpha1().TektonInstallerSets().DeleteCollection(
ctx,
metav1.DeleteOptions{},
metav1.ListOptions{LabelSelector: DEPRECATED_WEBHOOK_INSTALLERSET_LABEL},
)
if err != nil {
return err
}

// delete all the existing webhook installersets
labelSelector, err := common.LabelSelector(primaryLabelSelector)
if err != nil {
return err
}
return oc.OperatorV1alpha1().TektonInstallerSets().DeleteCollection(
ctx,
metav1.DeleteOptions{},
metav1.ListOptions{LabelSelector: WEBHOOK_INSTALLERSET_LABEL},
metav1.ListOptions{LabelSelector: labelSelector},
)
}

Expand All @@ -102,18 +133,10 @@ func createInstallerSet(ctx context.Context, oc clientset.Interface, manifest mf
}

func makeInstallerSet(manifest mf.Manifest) *v1alpha1.TektonInstallerSet {
//TODO: find ownerReference of the operator controller deployment and use that as the
// ownerReference for this TektonInstallerSet
return &v1alpha1.TektonInstallerSet{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-", "validating-mutating-webhoook"),
Labels: map[string]string{
WEBHOOK_INSTALLERSET_LABEL: "",
},
Annotations: map[string]string{
"releaseVersionKey": "v1.6.0",
},
//OwnerReferences: []metav1.OwnerReference{ownerRef},
Labels: primaryLabelSelector.MatchLabels,
},
Spec: v1alpha1.TektonInstallerSetSpec{
Manifests: manifest.Resources(),
Expand Down

0 comments on commit 2f0bf7c

Please sign in to comment.