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 role in openshift and include upgrade status #1750

Merged
merged 1 commit into from
Sep 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/openshift/base/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,12 @@ rules:
- resolution.tekton.dev
resources:
- resolutionrequests
- resolutionrequests/status
verbs:
- get
- list
- watch
- create
- delete
- update
- patch
41 changes: 41 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonconfig_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
)
Expand All @@ -25,13 +26,17 @@ const (
PreInstall apis.ConditionType = "PreInstall"
ComponentsReady apis.ConditionType = "ComponentsReady"
PostInstall apis.ConditionType = "PostInstall"
PreUpgrade apis.ConditionType = "PreUpgrade"
PostUpgrade apis.ConditionType = "PostUpgrade"
)

var (
configCondSet = apis.NewLivingConditionSet(
PreInstall,
ComponentsReady,
PostInstall,
PreUpgrade,
PostUpgrade,
)
)

Expand Down Expand Up @@ -98,6 +103,42 @@ func (tcs *TektonConfigStatus) MarkPostInstallFailed(msg string) {
"PostReconciliation failed with message: %s", msg)
}

func (tcs *TektonConfigStatus) MarkPreUpgradeComplete() bool {
condition := configCondSet.Manage(tcs).GetCondition(PreUpgrade)
if condition != nil && condition.Status == corev1.ConditionTrue {
return false
}
configCondSet.Manage(tcs).MarkTrue(PreUpgrade)
return true
}

func (tcs *TektonConfigStatus) MarkPostUpgradeComplete() bool {
condition := configCondSet.Manage(tcs).GetCondition(PostUpgrade)
if condition != nil && condition.Status == corev1.ConditionTrue {
return false
}
configCondSet.Manage(tcs).MarkTrue(PostUpgrade)
return true
}

func (tcs *TektonConfigStatus) MarkPreUpgradeFalse(reason, msg string) bool {
condition := configCondSet.Manage(tcs).GetCondition(PreUpgrade)
if condition != nil && condition.Status == corev1.ConditionFalse && condition.Reason == reason && condition.Message == msg {
return false
}
configCondSet.Manage(tcs).MarkFalse(PreUpgrade, reason, "%s", msg)
return true
}

func (tcs *TektonConfigStatus) MarkPostUpgradeFalse(reason, msg string) bool {
condition := configCondSet.Manage(tcs).GetCondition(PostUpgrade)
if condition != nil && condition.Status == corev1.ConditionFalse && condition.Reason == reason && condition.Message == msg {
return false
}
configCondSet.Manage(tcs).MarkFalse(PostUpgrade, reason, "%s", msg)
return true
}

// GetVersion gets the currently installed version of the component.
func (tcs *TektonConfigStatus) GetVersion() string {
return tcs.Version
Expand Down
38 changes: 32 additions & 6 deletions pkg/apis/operator/v1alpha1/tektonconfig_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestTektonConfigHappyPath(t *testing.T) {
apistest.CheckConditionOngoing(tc, PreInstall, t)
apistest.CheckConditionOngoing(tc, ComponentsReady, t)
apistest.CheckConditionOngoing(tc, PostInstall, t)
apistest.CheckConditionOngoing(tc, PreUpgrade, t)
apistest.CheckConditionOngoing(tc, PostUpgrade, t)

// Pre install completes execution
tc.MarkPreInstallComplete()
Expand All @@ -55,6 +57,20 @@ func TestTektonConfigHappyPath(t *testing.T) {
tc.MarkPostInstallComplete()
apistest.CheckConditionSucceeded(tc, PostInstall, t)

status := tc.MarkPreUpgradeComplete()
assert.Equal(t, true, status)
// returns false, as upgrade status already up to date
status = tc.MarkPreUpgradeComplete()
assert.Equal(t, false, status)
apistest.CheckConditionSucceeded(tc, PreUpgrade, t)

status = tc.MarkPostUpgradeComplete()
assert.Equal(t, true, status)
// returns false, as upgrade status already up to date
status = tc.MarkPostUpgradeComplete()
assert.Equal(t, false, status)
apistest.CheckConditionSucceeded(tc, PostUpgrade, t)

if ready := tc.IsReady(); !ready {
t.Errorf("tc.IsReady() = %v, want true", ready)
}
Expand All @@ -68,6 +84,8 @@ func TestTektonConfigErrorPath(t *testing.T) {
apistest.CheckConditionOngoing(tc, PreInstall, t)
apistest.CheckConditionOngoing(tc, ComponentsReady, t)
apistest.CheckConditionOngoing(tc, PostInstall, t)
apistest.CheckConditionOngoing(tc, PreUpgrade, t)
apistest.CheckConditionOngoing(tc, PostUpgrade, t)

// Pre install completes execution
tc.MarkPreInstallComplete()
Expand All @@ -84,6 +102,14 @@ func TestTektonConfigErrorPath(t *testing.T) {
tc.MarkPostInstallComplete()
apistest.CheckConditionSucceeded(tc, PostInstall, t)

status := tc.MarkPreUpgradeComplete()
assert.Equal(t, true, status)
apistest.CheckConditionSucceeded(tc, PreUpgrade, t)

status = tc.MarkPostUpgradeComplete()
assert.Equal(t, true, status)
apistest.CheckConditionSucceeded(tc, PostUpgrade, t)

if ready := tc.IsReady(); !ready {
t.Errorf("tc.IsReady() = %v, want true", ready)
}
Expand All @@ -98,35 +124,35 @@ func TestTektonConfigErrorPath(t *testing.T) {

}

func TestAppliedPreUpgradeVersion(t *testing.T) {
func TestPreUpgradeVersion(t *testing.T) {
tc := &TektonConfig{}

// should return empty
assert.Equal(t, tc.Status.GetPreUpgradeVersion(), "")

// update applied pre upgrade version
// update pre upgrade version
tc.Status.SetPreUpgradeVersion("foo")
assert.Equal(t, tc.Status.GetPreUpgradeVersion(), "foo")
assert.Equal(t, tc.Status.Annotations[PreUpgradeVersionKey], "foo")

// update applied pre upgrade version
// update pre upgrade version
tc.Status.SetPreUpgradeVersion("bar")
assert.Equal(t, tc.Status.GetPreUpgradeVersion(), "bar")
assert.Equal(t, tc.Status.Annotations[PreUpgradeVersionKey], "bar")
}

func TestAppliedPostUpgradeVersion(t *testing.T) {
func TestPostUpgradeVersion(t *testing.T) {
tc := &TektonConfig{}

// should return empty
assert.Equal(t, tc.Status.GetPostUpgradeVersion(), "")

// update applied post upgrade version
// update post upgrade version
tc.Status.SetPostUpgradeVersion("foo")
assert.Equal(t, tc.Status.GetPostUpgradeVersion(), "foo")
assert.Equal(t, tc.Status.Annotations[PostUpgradeVersionKey], "foo")

// update applied post upgrade version
// update post upgrade version
tc.Status.SetPostUpgradeVersion("bar")
assert.Equal(t, tc.Status.GetPostUpgradeVersion(), "bar")
assert.Equal(t, tc.Status.Annotations[PostUpgradeVersionKey], "bar")
Expand Down
14 changes: 2 additions & 12 deletions pkg/reconciler/shared/tektonconfig/tektonconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi
}

// run pre upgrade
isUpgradePerformed, err := r.upgrade.RunPreUpgrade(ctx)
err := r.upgrade.RunPreUpgrade(ctx)
if err != nil {
return err
}
// if upgrade executed, tektonConfig CR status will be updated
// hence calling the reconcile again
if isUpgradePerformed {
return v1alpha1.RECONCILE_AGAIN_ERR
}

tc.SetDefaults(ctx)
// Mark TektonConfig Instance as Not Ready if an upgrade is needed
Expand Down Expand Up @@ -209,15 +204,10 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, tc *v1alpha1.TektonConfi
}

// run post upgrade
isUpgradePerformed, err = r.upgrade.RunPostUpgrade(ctx)
err = r.upgrade.RunPostUpgrade(ctx)
if err != nil {
return err
}
// if upgrade executed, tektonConfig CR status will be updated
// hence calling the reconcile again
if isUpgradePerformed {
return v1alpha1.RECONCILE_AGAIN_ERR
}

return nil
}
Expand Down
28 changes: 16 additions & 12 deletions pkg/reconciler/shared/tektonconfig/upgrade/post_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package upgrade
import (
"context"

"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
"github.com/tektoncd/operator/pkg/client/clientset/versioned"
upgrade "github.com/tektoncd/operator/pkg/reconciler/shared/tektonconfig/upgrade/helper"
"go.uber.org/zap"
Expand All @@ -35,26 +34,31 @@ import (
func upgradeStorageVersion(ctx context.Context, logger *zap.SugaredLogger, k8sClient kubernetes.Interface, operatorClient versioned.Interface, restConfig *rest.Config) error {
// resources to be upgraded
crdGroups := []string{
"clusterinterceptors.triggers.tekton.dev",

// dashboard
"extensions.dashboard.tekton.dev",

// pipelines
"clustertasks.tekton.dev",
"clustertriggerbindings.triggers.tekton.dev",
"customruns.tekton.dev",
"eventlisteners.triggers.tekton.dev",
"extensions.dashboard.tekton.dev",
"interceptors.triggers.tekton.dev",
"pipelineruns.tekton.dev",
"pipelines.tekton.dev",
"resolutionrequests.resolution.tekton.dev",
"taskruns.tekton.dev",
"tasks.tekton.dev",
"verificationpolicies.tekton.dev",
"resolutionrequests.resolution.tekton.dev",

// Pipelines-as-code
"repositories.pipelinesascode.tekton.dev",

// triggers
"clusterinterceptors.triggers.tekton.dev",
"clustertriggerbindings.triggers.tekton.dev",
"eventlisteners.triggers.tekton.dev",
"interceptors.triggers.tekton.dev",
"triggerbindings.triggers.tekton.dev",
"triggers.triggers.tekton.dev",
"triggertemplates.triggers.tekton.dev",
"verificationpolicies.tekton.dev",
}

if v1alpha1.IsOpenShiftPlatform() {
crdGroups = append(crdGroups, "repositories.pipelinesascode.tekton.dev")
}

migrator := storageversion.NewMigrator(
Expand Down