Skip to content

Commit

Permalink
Remove adding default settings in CR
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush-garg committed Feb 6, 2024
1 parent 284e18f commit 62b61fb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ func (set *PACSettings) setPACDefaults() {
// Set the default values for additional PAc controller resources
func setAdditionalPACControllerDefault(additionalPACController map[string]AdditionalPACControllerConfig) {
for name, additionalPACInfo := range additionalPACController {
if additionalPACInfo.Settings == nil {
additionalPACInfo.Settings = map[string]string{}
}
settings.SetDefaults(additionalPACInfo.Settings)

if additionalPACInfo.Enable == nil {
additionalPACInfo.Enable = ptr.Bool(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ func TestSetAdditionalPACControllerDefault(t *testing.T) {
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")
assert.Equal(t, opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["remember-ok-to-test"], "true")
}

func TestSetAdditionalPACControllerDefaultHavingAdditionalPACController(t *testing.T) {
Expand Down Expand Up @@ -81,5 +79,4 @@ func TestSetAdditionalPACControllerDefaultHavingAdditionalPACController(t *testi
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")
assert.Equal(t, opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["remember-ok-to-test"], "true")
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ data:
error-detection-max-number-of-lines: "50"

# The default regexp used when we use the simple error detection
error-detection-simple-regexp: |
^(?P<filename>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+)?([ ]*)?(?P<error>.*)
error-detection-simple-regexp: "^(?P<filename>[^:]*):(?P<line>[0-9]+):(?P<column>[0-9]+):([ ]*)?(?P<error>.*)"

# Since public bitbucket doesn't have the concept of Secret, we need to be
# able to secure the request by querying https://ip-ranges.atlassian.com/,
Expand Down Expand Up @@ -118,10 +117,10 @@ data:
# Repo CR along a few other template variable, see documentation for more
# details
#
# custom-console-name: Console Name
# custom-console-url: https://url
# custom-console-url-pr-details: https://url/ns/{{ namespace }}/{{ pr }}
# custom-console-url-pr-tasklog: https://url/ns/{{ namespace }}/{{ pr }}/logs/{{ task }}
custom-console-name: ""
custom-console-url: ""
custom-console-url-pr-details: ""
custom-console-url-pr-tasklog: ""

kind: ConfigMap
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

mf "github.com/manifestival/manifestival"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings"
routev1 "github.com/openshift/api/route/v1"
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
"github.com/tektoncd/operator/pkg/reconciler/common"
Expand Down Expand Up @@ -217,9 +218,12 @@ func updateAdditionControllerConfigMap(config v1alpha1.AdditionalPACControllerCo

u.SetName(config.ConfigMapName)

if len(config.Settings) == 0 {
return nil
// apply the defaults here, we are not adding the defaults in CR
if config.Settings == nil {
config.Settings = map[string]string{}
}
settings.SetDefaults(config.Settings)

cm := &corev1.ConfigMap{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, cm)
if err != nil {
Expand Down

0 comments on commit 62b61fb

Please sign in to comment.