Skip to content
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
43 changes: 26 additions & 17 deletions pkg/reconciler/kubernetes/tektondashboard/tektondashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
pipelineinformer "github.com/tektoncd/operator/pkg/client/informers/externalversions/operator/v1alpha1"
tektondashboardreconciler "github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektondashboard"
"github.com/tektoncd/operator/pkg/reconciler/common"
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset"
"github.com/tektoncd/operator/pkg/reconciler/shared/hash"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -62,7 +63,14 @@ type Reconciler struct {
var _ tektondashboardreconciler.Interface = (*Reconciler)(nil)
var _ tektondashboardreconciler.Finalizer = (*Reconciler)(nil)

var watchedResourceName = "dashboard"
var (
ls = metav1.LabelSelector{
MatchLabels: map[string]string{
v1alpha1.CreatedByKey: createdByValue,
v1alpha1.InstallerSetType: v1alpha1.DashboardResourceName,
},
}
)

const createdByValue = "TektonDashboard"

Expand All @@ -86,11 +94,6 @@ func (r *Reconciler) FinalizeKind(ctx context.Context, original *v1alpha1.Tekton
return err
}

ls := metav1.LabelSelector{
MatchLabels: map[string]string{
v1alpha1.CreatedByKey: createdByValue,
},
}
labelSelector, err := common.LabelSelector(ls)
if err != nil {
return err
Expand Down Expand Up @@ -119,9 +122,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb

logger.Infow("Reconciling TektonDashboards", "status", td.Status)

if td.GetName() != watchedResourceName {
if td.GetName() != v1alpha1.DashboardResourceName {
msg := fmt.Sprintf("Resource ignored, Expected Name: %s, Got Name: %s",
watchedResourceName,
v1alpha1.DashboardResourceName,
td.GetName(),
)
logger.Error(msg)
Expand Down Expand Up @@ -152,11 +155,16 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb
// Mark PreReconcile Complete
td.Status.MarkPreReconcilerComplete()

// Check if an tekton installer set already exists, if not then create
existingInstallerSet := td.Status.GetTektonInstallerSet()
// Check if an tektoninstallerset already exists, if not then create
labelSelector, err := common.LabelSelector(ls)
if err != nil {
return err
}
existingInstallerSet, err := tektoninstallerset.CurrentInstallerSetName(ctx, r.operatorClientSet, labelSelector)
if err != nil {
return err
}
if existingInstallerSet == "" {
td.Status.MarkInstallerSetNotAvailable("Dashboard Installer Set Not Available")

createdIs, err := r.createInstallerSet(ctx, td)
if err != nil {
return err
Expand All @@ -181,7 +189,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, td *v1alpha1.TektonDashb
}

installerSetTargetNamespace := installedTIS.Annotations[v1alpha1.TargetNamespaceKey]
installerSetReleaseVersion := installedTIS.Annotations[v1alpha1.ReleaseVersionKey]
installerSetReleaseVersion := installedTIS.Labels[v1alpha1.ReleaseVersionKey]

// Check if TargetNamespace of existing TektonInstallerSet is same as expected
// Check if Release Version in TektonInstallerSet is same as expected
Expand Down Expand Up @@ -344,7 +352,7 @@ func (r *Reconciler) createInstallerSet(ctx context.Context, td *v1alpha1.Tekton
}

// create installer set
tis := makeInstallerSet(td, manifest, specHash, r.operatorVersion)
tis := r.makeInstallerSet(td, manifest, specHash)
createdIs, err := r.operatorClientSet.OperatorV1alpha1().TektonInstallerSets().
Create(ctx, tis, metav1.CreateOptions{})
if err != nil {
Expand All @@ -353,16 +361,17 @@ func (r *Reconciler) createInstallerSet(ctx context.Context, td *v1alpha1.Tekton
return createdIs, nil
}

func makeInstallerSet(td *v1alpha1.TektonDashboard, manifest mf.Manifest, tdSpecHash, releaseVersion string) *v1alpha1.TektonInstallerSet {
func (r *Reconciler) makeInstallerSet(td *v1alpha1.TektonDashboard, manifest mf.Manifest, tdSpecHash string) *v1alpha1.TektonInstallerSet {
ownerRef := *metav1.NewControllerRef(td, td.GetGroupVersionKind())
return &v1alpha1.TektonInstallerSet{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-", v1alpha1.DashboardResourceName),
Labels: map[string]string{
v1alpha1.CreatedByKey: createdByValue,
v1alpha1.CreatedByKey: createdByValue,
v1alpha1.InstallerSetType: v1alpha1.DashboardResourceName,
v1alpha1.ReleaseVersionKey: r.operatorVersion,
},
Annotations: map[string]string{
v1alpha1.ReleaseVersionKey: releaseVersion,
v1alpha1.TargetNamespaceKey: td.Spec.TargetNamespace,
v1alpha1.LastAppliedHashKey: tdSpecHash,
},
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/kubernetes/tektondashboarddeployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func TestTektonDashboardsDeployment(t *testing.T) {
resources.AssertTektonDashboardCRReadyStatus(t, clients, crNames)
})

// Test if TektonInstallerSets are created.
t.Run("verify-dashboard-installersets", func(t *testing.T) {
resources.AssertDashboardInstallerSets(t, clients)
})

// Delete the TektonDashboard CR instance to see if all resources will be removed
t.Run("delete-dashboard", func(t *testing.T) {
resources.AssertTektonDashboardCRReadyStatus(t, clients, crNames)
Expand Down
18 changes: 9 additions & 9 deletions test/resources/tektonaddons.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ func AssertTektonAddonCRReadyStatus(t *testing.T, clients *utils.Clients, names

// AssertTektonInstallerSets verifies if the TektonInstallerSets are created.
func AssertTektonInstallerSets(t *testing.T, clients *utils.Clients) {
assertInstallerSetsForAddon(t, clients, tektonaddon.ClusterTaskInstallerSet)
assertInstallerSetsForAddon(t, clients, tektonaddon.VersionedClusterTaskInstallerSet)
assertInstallerSetsForAddon(t, clients, tektonaddon.PipelinesTemplateInstallerSet)
assertInstallerSetsForAddon(t, clients, tektonaddon.TriggersResourcesInstallerSet)
assertInstallerSetsForAddon(t, clients, tektonaddon.ConsoleCLIInstallerSet)
assertInstallerSetsForAddon(t, clients, tektonaddon.MiscellaneousResourcesInstallerSet)
assertInstallerSets(t, clients, tektonaddon.ClusterTaskInstallerSet)
assertInstallerSets(t, clients, tektonaddon.VersionedClusterTaskInstallerSet)
assertInstallerSets(t, clients, tektonaddon.PipelinesTemplateInstallerSet)
assertInstallerSets(t, clients, tektonaddon.TriggersResourcesInstallerSet)
assertInstallerSets(t, clients, tektonaddon.ConsoleCLIInstallerSet)
assertInstallerSets(t, clients, tektonaddon.MiscellaneousResourcesInstallerSet)
}

func assertInstallerSetsForAddon(t *testing.T, clients *utils.Clients, component string) {
func assertInstallerSets(t *testing.T, clients *utils.Clients, component string) {
ls := metav1.LabelSelector{
MatchLabels: map[string]string{
v1alpha1.InstallerSetType: component,
Expand All @@ -114,13 +114,13 @@ func assertInstallerSetsForAddon(t *testing.T, clients *utils.Clients, component
if err != nil {
t.Fatal(err)
}
clusterTaskIS, err := clients.TektonInstallerSet().List(context.TODO(), metav1.ListOptions{
installerSets, err := clients.TektonInstallerSet().List(context.TODO(), metav1.ListOptions{
LabelSelector: labelSelector,
})
if err != nil {
t.Fatalf("failed to get TektonInstallerSet for %s : %v", component, err)
}
if len(clusterTaskIS.Items) > 1 {
if len(installerSets.Items) > 1 {
t.Fatalf("multiple installer sets for %s TektonInstallerSet", component)
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/resources/tektondashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func IsTektonDashboardReady(s *v1alpha1.TektonDashboard, err error) (bool, error
return s.Status.IsReady(), err
}

// AssertTektonInstallerSets verifies if the TektonInstallerSets are created.
func AssertDashboardInstallerSets(t *testing.T, clients *utils.Clients) {
assertInstallerSets(t, clients, v1alpha1.DashboardResourceName)
}

// AssertTektonDashboardCRReadyStatus verifies if the TektonDashboard reaches the READY status.
func AssertTektonDashboardCRReadyStatus(t *testing.T, clients *utils.Clients, names utils.ResourceNames) {
if _, err := WaitForTektonDashboardState(clients.TektonDashboard(), names.TektonDashboard,
Expand Down