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 7, 2022
1 parent a9b2343 commit 95c0925
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 124 deletions.
8 changes: 8 additions & 0 deletions pkg/reconciler/kubernetes/tektoninstallerset/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ const (
CreatedByKey = "operator.tekton.dev/created-by"
ReleaseVersionKey = "operator.tekton.dev/release-version"
TargetNamespaceKey = "operator.tekton.dev/target-namespace"
InstallerSetType = "operator.tekton.dev/type"

ClusterTaskInstallerSet = "ClusterTask"
PipelinesTemplateInstallerSet = "PipelinesTemplate"
TriggersResourcesInstallerSet = "TriggersResources"
ConsoleCLIInstallerSet = "ConsoleCLI"
MiscellaneousResourcesInstallerSet = "MiscellaneousResources"
CreatedByValue = "TektonAddon"
)
40 changes: 17 additions & 23 deletions pkg/reconciler/openshift/tektonaddon/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,27 @@ 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, tektoninstallerset.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 {
tektoninstallerset.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, tektoninstallerset.MiscellaneousResourcesInstallerSet),
})
if err != nil {
if apierrors.IsNotFound(err) {
manifest, err := getMiscellaneousManifest(ctx, addon, oe.manifest, comp)
Expand All @@ -120,7 +116,7 @@ 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 {
tektoninstallerset.MiscellaneousResourcesInstallerSet, "addon-openshift"); err != nil {
return err
}
}
Expand All @@ -134,7 +130,7 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te
}

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

if lastAppliedHash != expectedSpecHash {

Expand All @@ -144,33 +140,31 @@ 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, tektoninstallerset.MiscellaneousResourcesInstallerSet),
})
if err != nil {
logger.Error("failed to get InstallerSet: %s", err)
return err
}

ready := installedAddonIS.Status.GetCondition(apis.ConditionReady)
ready := installedAddonIS.Items[0].Status.GetCondition(apis.ConditionReady)
if ready == nil {
return v1alpha1.RECONCILE_AGAIN_ERR
}
Expand All @@ -180,7 +174,7 @@ 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, tektoninstallerset.ConsoleCLIInstallerSet)
if err != nil {
return err
}
Expand All @@ -203,7 +197,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 {
tektoninstallerset.ConsoleCLIInstallerSet, "addon-consolecli"); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit 95c0925

Please sign in to comment.