Skip to content

Commit

Permalink
Removes the resources based on the profile set
Browse files Browse the repository at this point in the history
This patch includes:

  - When the Tekton Config profile is changed, based on the profile set
    components are deleted

  - For example:

      * If the profile is changed from all to basic:
          * In case of Kubernetes: Dashboard Component is deleted
          * In case of Openshift: Addon Component is deleted

Fixes: #358

Signed-off-by: Puneet Punamiya <[email protected]>
  • Loading branch information
PuneetPunamiya committed Aug 27, 2021
1 parent f66f13e commit 4297958
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pkg/reconciler/kubernetes/tektonconfig/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
operatorclient "github.com/tektoncd/operator/pkg/client/injection/client"
"github.com/tektoncd/operator/pkg/reconciler/common"
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektonconfig/extension"
tt "github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektonconfig/trigger"
)

func KubernetesExtension(ctx context.Context) common.Extension {
Expand All @@ -45,9 +46,40 @@ func (oe kubernetesExtension) PreReconcile(context.Context, v1alpha1.TektonCompo
}
func (oe kubernetesExtension) PostReconcile(ctx context.Context, comp v1alpha1.TektonComponent) error {
configInstance := comp.(*v1alpha1.TektonConfig)
if configInstance.Spec.Profile == common.ProfileAll {

switch configInstance.Spec.Profile {
case common.ProfileAll:
return extension.CreateDashboardCR(comp, oe.operatorClientSet.OperatorV1alpha1())

case common.ProfileBasic:
_, err := extension.GetDashboard(oe.operatorClientSet.OperatorV1alpha1().TektonDashboards(), common.DashboardResourceName)
if err != nil {
return err
}
return extension.TektonDashboardCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonDashboards(), common.DashboardResourceName)

case common.ProfileLite:
dashboard, err := extension.GetDashboard(oe.operatorClientSet.OperatorV1alpha1().TektonDashboards(), common.DashboardResourceName)
if dashboard != nil {
err := extension.TektonDashboardCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonDashboards(), common.DashboardResourceName)
if err != nil {
return err
}
}
if err != nil {
trigger, err := tt.GetTrigger(oe.operatorClientSet.OperatorV1alpha1().TektonTriggers(), common.TriggerResourceName)
if trigger != nil {
err := tt.TektonTriggerCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonTriggers(), common.TriggerResourceName)
if err != nil {
return err
}
}
if err != nil {
return err
}
}
}

return nil
}
func (oe kubernetesExtension) Finalize(ctx context.Context, comp v1alpha1.TektonComponent) error {
Expand Down
7 changes: 7 additions & 0 deletions pkg/reconciler/openshift/tektonconfig/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.Te
return err
}
}

if configInstance.Spec.Profile == common.ProfileBasic {
addon, _ := extension.GetAddon(oe.operatorClientSet.OperatorV1alpha1().TektonAddons(), common.DashboardResourceName)
if addon != nil {
return extension.TektonAddonCRDelete(oe.operatorClientSet.OperatorV1alpha1().TektonAddons(), common.AddonResourceName)
}
}
return nil
}
func (oe openshiftExtension) Finalize(ctx context.Context, comp v1alpha1.TektonComponent) error {
Expand Down

0 comments on commit 4297958

Please sign in to comment.