Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple installersets for tektonaddon #574

Merged
Merged
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
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"
)
44 changes: 21 additions & 23 deletions pkg/reconciler/openshift/tektonaddon/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,31 +87,29 @@ 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
}

// Check if installer set is already created
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,9 +118,10 @@ 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 {
nikhil-thomas marked this conversation as resolved.
Show resolved Hide resolved
return err
}
return v1alpha1.RECONCILE_AGAIN_ERR
}
logger.Error("failed to get InstallerSet: %s", err)
return err
Expand All @@ -134,7 +133,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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have a check for len for Items ? just to be safe before accessing


if lastAppliedHash != expectedSpecHash {

Expand All @@ -144,33 +143,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, 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 +177,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 +201,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