Skip to content

Commit

Permalink
Fix multiple installersets for tektonaddon
Browse files Browse the repository at this point in the history
  • Loading branch information
savitaashture committed Jan 11, 2022
1 parent a9b2343 commit ec659de
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 132 deletions.
1 change: 1 addition & 0 deletions pkg/reconciler/kubernetes/tektoninstallerset/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ const (
CreatedByKey = "operator.tekton.dev/created-by"
ReleaseVersionKey = "operator.tekton.dev/release-version"
TargetNamespaceKey = "operator.tekton.dev/target-namespace"
InstallerSetType = "operator.tekton.dev/type"
)
26 changes: 26 additions & 0 deletions pkg/reconciler/openshift/tektonaddon/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2022 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package tektonaddon

const (
ClusterTaskInstallerSet = "ClusterTask"
PipelinesTemplateInstallerSet = "PipelinesTemplate"
TriggersResourcesInstallerSet = "TriggersResources"
ConsoleCLIInstallerSet = "ConsoleCLI"
MiscellaneousResourcesInstallerSet = "MiscellaneousResources"
CreatedByValue = "TektonAddon"
)
50 changes: 27 additions & 23 deletions pkg/reconciler/openshift/tektonaddon/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,28 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te
logger := logging.FromContext(ctx)
addon := comp.(*v1alpha1.TektonAddon)

exist, err := checkIfInstallerSetExist(ctx, oe.operatorClientSet, oe.version, addon, miscellaneousResourcesInstallerSet)
exist, err := checkIfInstallerSetExist(ctx, oe.operatorClientSet, oe.version,
fmt.Sprintf("%s=%s", tektoninstallerset.InstallerSetType, MiscellaneousResourcesInstallerSet))
if err != nil {
return err
}
if !exist {

manifest, err := getMiscellaneousManifest(ctx, addon, oe.manifest, comp)
if err != nil {
return err
}

if err := createInstallerSet(ctx, oe.operatorClientSet, addon, manifest, oe.version,
miscellaneousResourcesInstallerSet, "addon-openshift"); err != nil {
MiscellaneousResourcesInstallerSet, "addon-openshift"); err != nil {
return err
}
}

// Check if installer set is already created
compInstallerSet, ok := addon.Status.AddonsInstallerSet[miscellaneousResourcesInstallerSet]
if !ok {
return v1alpha1.RECONCILE_AGAIN_ERR
}

installedTIS, err := oe.operatorClientSet.OperatorV1alpha1().TektonInstallerSets().
Get(ctx, compInstallerSet, metav1.GetOptions{})
List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", tektoninstallerset.InstallerSetType, MiscellaneousResourcesInstallerSet),
})
if err != nil {
if apierrors.IsNotFound(err) {
manifest, err := getMiscellaneousManifest(ctx, addon, oe.manifest, comp)
Expand All @@ -120,21 +117,25 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te
}

if err := createInstallerSet(ctx, oe.operatorClientSet, addon, manifest, oe.version,
miscellaneousResourcesInstallerSet, "addon-openshift"); err != nil {
MiscellaneousResourcesInstallerSet, "addon-openshift"); err != nil {
return err
}
}
logger.Error("failed to get InstallerSet: %s", err)
return err
}

if len(installedTIS.Items) == 0 {
return v1alpha1.RECONCILE_AGAIN_ERR
}

expectedSpecHash, err := hash.Compute(addon.Spec)
if err != nil {
return err
}

// spec hash stored on installerSet
lastAppliedHash := installedTIS.GetAnnotations()[tektoninstallerset.LastAppliedHashKey]
lastAppliedHash := installedTIS.Items[0].GetAnnotations()[tektoninstallerset.LastAppliedHashKey]

if lastAppliedHash != expectedSpecHash {

Expand All @@ -144,33 +145,35 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te
}

// Update the spec hash
current := installedTIS.GetAnnotations()
current := installedTIS.Items[0].GetAnnotations()
current[tektoninstallerset.LastAppliedHashKey] = expectedSpecHash
installedTIS.SetAnnotations(current)
installedTIS.Items[0].SetAnnotations(current)

// Update the manifests
installedTIS.Spec.Manifests = manifest.Resources()
installedTIS.Items[0].Spec.Manifests = manifest.Resources()

if _, err = oe.operatorClientSet.OperatorV1alpha1().TektonInstallerSets().
Update(ctx, installedTIS, metav1.UpdateOptions{}); err != nil {
Update(ctx, &installedTIS.Items[0], metav1.UpdateOptions{}); err != nil {
return err
}

return v1alpha1.RECONCILE_AGAIN_ERR
}

existingInstallerSet, ok := addon.Status.AddonsInstallerSet[miscellaneousResourcesInstallerSet]
if !ok {
return v1alpha1.RECONCILE_AGAIN_ERR
}
installedAddonIS, err := oe.operatorClientSet.OperatorV1alpha1().TektonInstallerSets().
Get(ctx, existingInstallerSet, metav1.GetOptions{})
List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", tektoninstallerset.InstallerSetType, MiscellaneousResourcesInstallerSet),
})
if err != nil {
logger.Error("failed to get InstallerSet: %s", err)
return err
}

ready := installedAddonIS.Status.GetCondition(apis.ConditionReady)
if len(installedAddonIS.Items) == 0 {
return v1alpha1.RECONCILE_AGAIN_ERR
}

ready := installedAddonIS.Items[0].Status.GetCondition(apis.ConditionReady)
if ready == nil {
return v1alpha1.RECONCILE_AGAIN_ERR
}
Expand All @@ -180,7 +183,8 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te
}

consolecliManifest := oe.manifest
exist, err = checkIfInstallerSetExist(ctx, oe.operatorClientSet, oe.version, addon, consoleCLIInstallerSet)
exist, err = checkIfInstallerSetExist(ctx, oe.operatorClientSet, oe.version,
fmt.Sprintf("%s=%s", tektoninstallerset.InstallerSetType, ConsoleCLIInstallerSet))
if err != nil {
return err
}
Expand All @@ -203,7 +207,7 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te
}

if err := createInstallerSet(ctx, oe.operatorClientSet, addon, consolecliManifest, oe.version,
consoleCLIInstallerSet, "addon-consolecli"); err != nil {
ConsoleCLIInstallerSet, "addon-consolecli"); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit ec659de

Please sign in to comment.