Skip to content

Commit

Permalink
Add enable option for every additional pac
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush-garg committed Feb 5, 2024
1 parent 07d65a0 commit 5d544dc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/TektonConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ spec:
pipelinesAsCode:
additionalPACControllers:
controllerA:
enable: true
configMapName:
secretName:
settings:
Expand Down Expand Up @@ -475,10 +476,12 @@ Example:
pipelinesAsCode:
additionalPACControllers:
controllerName:
enable:
configMapName:
secretName:
settings:
```
Field `enable` is optional with default value to true. You can use this field to disable the particular additional PAC controller, without removing the details.

Field `configMapName` is optional and used to set the ConfigMap name of additional Pipelines As Controller in the deployment. If user doesn't provides any value then Operator will add controllerName + `-configmap` as default value.
If user creates configMap with name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package v1alpha1
import (
"context"

"knative.dev/pkg/ptr"

"github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings"
)

Expand Down Expand Up @@ -48,6 +50,9 @@ func setAdditionalPACControllerDefault(additionalPACController map[string]Additi
}
settings.SetDefaults(additionalPACInfo.Settings)

if additionalPACInfo.Enable == nil {
additionalPACInfo.Enable = ptr.Bool(true)
}
if additionalPACInfo.ConfigMapName == "" {
additionalPACInfo.ConfigMapName = name + "-configmap"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package v1alpha1
import (
"testing"

"knative.dev/pkg/ptr"

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -41,6 +43,7 @@ func TestSetAdditionalPACControllerDefault(t *testing.T) {

opacCR.Spec.PACSettings.setPACDefaults()

assert.Equal(t, *opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Enable, true)
assert.Equal(t, opacCR.Spec.PACSettings.AdditionalPACControllers["test"].ConfigMapName, "test-configmap")
assert.Equal(t, opacCR.Spec.PACSettings.AdditionalPACControllers["test"].SecretName, "test-secret")
assert.Equal(t, opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["application-name"], "Pipelines as Code CI")
Expand All @@ -58,6 +61,7 @@ func TestSetAdditionalPACControllerDefaultHavingAdditionalPACController(t *testi
Settings: map[string]string{},
AdditionalPACControllers: map[string]AdditionalPACControllerConfig{
"test": {
Enable: ptr.Bool(false),
ConfigMapName: "test-configmap",
SecretName: "test-secret",
Settings: map[string]string{
Expand All @@ -73,6 +77,7 @@ func TestSetAdditionalPACControllerDefaultHavingAdditionalPACController(t *testi

opacCR.Spec.PACSettings.setPACDefaults()

assert.Equal(t, *opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Enable, false)
assert.Equal(t, opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["application-name"], "Additional PACController CI")
assert.Equal(t, opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["custom-console-name"], "custom")
assert.Equal(t, opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["custom-console-url"], "https://custom.com")
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/operator/v1alpha1/openshiftpipelinesascode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type PACSettings struct {

// AdditionalPACControllerConfig contains config for additionalPACControllers
type AdditionalPACControllerConfig struct {
// Enable or disable this additional pipelines as code instance by changing this bool
// +optional
Enable *bool `json:"enable,omitempty"`
// Name of the additional controller configMap
// +optional
ConfigMapName string `json:"configMapName,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions pkg/reconciler/openshift/openshiftpipelinesascode/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, pac *v1alpha1.OpenShiftP
}

for name, pacInfo := range pac.Spec.PACSettings.AdditionalPACControllers {
// if it is not enabled then skip creating
if !*pacInfo.Enable {
continue
}

additionalPACControllerManifest := r.additionalPACManifest
if pacInfo.ConfigMapName == pipelinesAsCodeCM {
additionalPACControllerManifest = additionalPACControllerManifest.Filter(mf.Not(mf.ByKind("ConfigMap")))
Expand Down Expand Up @@ -139,9 +144,9 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, pac *v1alpha1.OpenShiftP
// remove the prefix custom-
name := strings.TrimPrefix(setTypeValue, fmt.Sprintf(client.InstallerTypeCustom+"-"))
// check if the name exist in additionalPac Controller
_, ok := pac.Spec.PACSettings.AdditionalPACControllers[name]
// if not, delete the installerset
if !ok {
additionalPACinfo, ok := pac.Spec.PACSettings.AdditionalPACControllers[name]
// if not exist with same name or marked disable, delete the installerset
if !ok || !*additionalPACinfo.Enable {
if err := r.installerSetClient.CleanupCustomSet(ctx, name); err != nil {
return err
}
Expand Down

0 comments on commit 5d544dc

Please sign in to comment.