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

Add pac cont #1

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ba9e662
adds additional PAC controller
pratap0007 Jan 26, 2024
4c2d7f1
handle status and configmap creation
pratap0007 Jan 29, 2024
b7533a9
Refactoring tranformer
piyush-garg Jan 29, 2024
621bdf3
adds transformers
pratap0007 Jan 29, 2024
d325ffc
adds tests for transformers and remove additional code
pratap0007 Jan 30, 2024
879a479
Add basic structure for defaulting and validation:
piyush-garg Jan 30, 2024
9886ea0
adds validations and default setting logic, and also adds tests
pratap0007 Jan 30, 2024
1f78590
modify tranformer
pratap0007 Jan 30, 2024
c932f41
Add reconciler
piyush-garg Jan 31, 2024
c591e82
Add fixes to make reconciler work
piyush-garg Feb 1, 2024
ae318e7
Refactor transformer
piyush-garg Feb 2, 2024
f9992d8
adds vaildation and default test
pratap0007 Feb 2, 2024
90bd044
remove auto_generate file
piyush-garg Feb 2, 2024
653c3bf
Rever script changes
piyush-garg Feb 2, 2024
30bd603
Refactor api pkg
piyush-garg Feb 2, 2024
d014e98
Refactor reconciler
piyush-garg Feb 2, 2024
1e93d29
Fix validation not working
piyush-garg Feb 4, 2024
05ce5ef
adds instructions to deploy additional pac controller
pratap0007 Feb 5, 2024
5f06a9b
Add enable option for every additional pac
piyush-garg Feb 5, 2024
4ca69ab
Remove adding default settings in CR
piyush-garg Feb 6, 2024
de2a8ea
Adds e2e test for additional pac controller
pratap0007 Feb 6, 2024
fd426a6
Fix suffix name and lenght restrictions
piyush-garg Feb 6, 2024
23b237c
Refactor e2e tests
piyush-garg Feb 7, 2024
48d8876
Refactor validation
piyush-garg Feb 7, 2024
29d480d
Refactor reconciler
piyush-garg Feb 7, 2024
8953fac
Refactor docs and names
piyush-garg Feb 7, 2024
54578a6
Refactor based on review comments
piyush-garg Feb 7, 2024
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
58 changes: 57 additions & 1 deletion docs/OpenShiftPipelinesAsCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ It is recommended that you install OpenShiftPipelinesAsCode through [TektonConfi
metadata:
name: pipelines-as-code
spec:
additionalPACControllers:
controllername:
enable: true
configMapName:
secretName:
settings:
enable: true
settings:
application-name: Pipelines as Code CI
auto-configure-new-github-repo: "false"
Expand Down Expand Up @@ -57,12 +64,61 @@ The recommended way to update the OpenShiftPipelinesAsCode CR is using [TektonCo

Set this field to provide the namespace in which you want to install the PipelinesAsCode component.

### Properties
### Properties (Optional)

The fields have default values so even if the user has not passed them in CR, operator will add them. The user can later change
them as per their need.

Details of the field can be found in [OpenShift Pipelines As Code Settings][pac-config]

#### Additional Pipelines As Controller (Optional)

If users want to deploy additional Pipelines As Code controller on their cluster along with default Pipelines As Code
controller then they need to provide the `additionalPACControllers` field in the `pipelinesAsCode` section.

Example:

```yaml
pipelinesAsCode:
additionalPACControllers: # can provide a list of controllers
controllername:
enable:
configMapName:
secretName:
settings:
```

- `controllerName` is the unique name of the new controller, should not be more than 25 characters and should follow k8s naming rules.

- `enable` is optional with default value to true. You can use this field to disable the additional PAC controller
without removing the details from the CR.

- `configMapName` is optional and is to provide the ConfigMap name of additional PAC Controller. If user doesn't
provide any value then Operator will add controllerName + `-pipelines-as-code-configmap` as default value. If user
provides configMap name as `pipelines-as-code` for additional Pipelines As Code controller, then operator will not create
the configMap and the default `pipeline-as-code` configMap will be used with default settings.

- `secretName` is optional and is to provide the secret name of additional PAC Controller. If user does not provide any
value then operator will add controllerName + `-pipelines-as-code-secret` as default value to be added to deployment env.

- `settings` is optional and used to set the settings in the configMap of additional PAC Controller. For the fields whose
are not provided, default value will be used. You can check them [here](https://pipelinesascode.com/docs/install/settings/#pipelines-as-code-configuration-settings).
Also, if configmap name is provided as `pipelines-as-code` then these settings will not be taken.

> **NOTE:** Users can deploy multiple additional PAC Controller by providing multiple entries in `additionalPACControllers` field.

Example:

```yaml
pipelinesAsCode:
additionalPACControllers:
firstcontroller:
enable: true
secondcontroller:
enable: true
configMapName: second-config
secretName: second-secret
```

[PipelinesAsCode]:https://github.com/openshift-pipelines/pipelines-as-code
[pac-config]:https://pipelinesascode.com/docs/install/settings/#pipelines-as-code-configuration-settings
24 changes: 18 additions & 6 deletions docs/TektonConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ The TektonConfig CR provides the following features
platforms:
openshift:
pipelinesAsCode:
additionalPACControllers:
<controllerName>:
enable: true
configMapName:
secretName:
settings:
enable: true
settings:
application-name: Pipelines as Code CI
Expand Down Expand Up @@ -417,6 +423,12 @@ Example:
platforms:
openshift:
pipelinesAsCode:
additionalPACControllers:
controllername:
enable: true
configMapName:
secretName:
settings:
enable: true
settings:
application-name: Pipelines as Code CI
Expand All @@ -440,12 +452,6 @@ platforms:

**NOTE**: OpenShiftPipelinesAsCode is currently available for the OpenShift Platform only.

[node-selector]:https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector
[tolerations]:https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/
[schedule]:https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#cron-schedule-syntax
[priorityClassName]: https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#pod-priority
[priorityClass]: https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass

### Additional fields as `options`
There is a field called `options` available in all the components.<br>

Expand Down Expand Up @@ -636,3 +642,9 @@ The following fields are supported in `HorizontalPodAutoscaler` (aka HPA)
* `scaleDown` - replaces scaleDown with this, if not empty

**NOTE**: If a Deployment or StatefulSet has a Horizontal Pod Autoscaling (HPA) and is in active state, Operator will not control the replicas to that resource. However if `status.desiredReplicas` and `spec.minReplicas` not present in HPA, operator takes the control. Also if HPA disabled, operator takes control. Even though the operator takes the control, the replicas value will be adjusted to the hpa's scaling range.

[node-selector]:https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector
[tolerations]:https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/
[schedule]:https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#cron-schedule-syntax
[priorityClassName]: https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#pod-priority
[priorityClass]: https://kubernetes.io/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass
2 changes: 1 addition & 1 deletion pkg/apis/operator/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
LastAppliedHashKey = "operator.tekton.dev/last-applied-hash"
CreatedByKey = "operator.tekton.dev/created-by"
ReleaseVersionKey = "operator.tekton.dev/release-version"
Component = "operator.tekton.dev/component" // Used in case a component has sub-components eg TektonHub
ComponentKey = "operator.tekton.dev/component" // Used in case a component has sub-components eg OpenShiftPipelineAsCode
ReleaseMinorVersionKey = "operator.tekton.dev/release-minor-version"
TargetNamespaceKey = "operator.tekton.dev/target-namespace"
InstallerSetType = "operator.tekton.dev/type"
Expand Down
26 changes: 24 additions & 2 deletions pkg/apis/operator/v1alpha1/openshiftpipelinesascode_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,42 @@ package v1alpha1

import (
"context"
"fmt"

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

func (pac *OpenShiftPipelinesAsCode) SetDefaults(ctx context.Context) {
if pac.Spec.PACSettings.Settings == nil {
pac.Spec.PACSettings.Settings = map[string]string{}
}
setPACDefaults(pac.Spec.PACSettings)
if pac.Spec.PACSettings.AdditionalPACControllers == nil {
pac.Spec.PACSettings.AdditionalPACControllers = map[string]AdditionalPACControllerConfig{}
}
pac.Spec.PACSettings.setPACDefaults()
}

func setPACDefaults(set PACSettings) {
func (set *PACSettings) setPACDefaults() {
if set.Settings == nil {
set.Settings = map[string]string{}
}
settings.SetDefaults(set.Settings)
setAdditionalPACControllerDefault(set.AdditionalPACControllers)
}

// Set the default values for additional PAc controller resources
func setAdditionalPACControllerDefault(additionalPACController map[string]AdditionalPACControllerConfig) {
for name, additionalPACInfo := range additionalPACController {
if additionalPACInfo.Enable == nil {
additionalPACInfo.Enable = ptr.Bool(true)
}
if additionalPACInfo.ConfigMapName == "" {
additionalPACInfo.ConfigMapName = fmt.Sprintf("%s-pipelines-as-code-configmap", name)
}
if additionalPACInfo.SecretName == "" {
additionalPACInfo.SecretName = fmt.Sprintf("%s-pipelines-as-code-secret", name)
}
additionalPACController[name] = additionalPACInfo
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright 2024 The Tekton Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"testing"

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/ptr"
)

func TestSetAdditionalPACControllerDefault(t *testing.T) {
opacCR := &OpenShiftPipelinesAsCode{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: OpenShiftPipelinesAsCodeSpec{
PACSettings: PACSettings{
Settings: map[string]string{},
AdditionalPACControllers: map[string]AdditionalPACControllerConfig{
"test": {},
},
},
},
}

opacCR.Spec.PACSettings.setPACDefaults()

assert.Equal(t, true, *opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Enable)
assert.Equal(t, "test-pipelines-as-code-configmap", opacCR.Spec.PACSettings.AdditionalPACControllers["test"].ConfigMapName)
assert.Equal(t, "test-pipelines-as-code-secret", opacCR.Spec.PACSettings.AdditionalPACControllers["test"].SecretName)
}

func TestSetAdditionalPACControllerDefaultHavingAdditionalPACController(t *testing.T) {
opacCR := &OpenShiftPipelinesAsCode{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: OpenShiftPipelinesAsCodeSpec{
PACSettings: PACSettings{
Settings: map[string]string{},
AdditionalPACControllers: map[string]AdditionalPACControllerConfig{
"test": {
Enable: ptr.Bool(false),
ConfigMapName: "test-configmap",
SecretName: "test-secret",
Settings: map[string]string{
"application-name": "Additional PACController CI",
"custom-console-name": "custom",
"custom-console-url": "https://custom.com",
},
},
},
},
},
}

opacCR.Spec.PACSettings.setPACDefaults()

assert.Equal(t, false, *opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Enable)
assert.Equal(t, "Additional PACController CI", opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["application-name"])
assert.Equal(t, "custom", opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["custom-console-name"])
assert.Equal(t, "https://custom.com", opacCR.Spec.PACSettings.AdditionalPACControllers["test"].Settings["custom-console-url"])
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ var (
PreReconciler,
InstallerSetAvailable,
InstallerSetReady,
AdditionalPACControllerInstalled,
PostReconciler,
)
)

const (
AdditionalPACControllerInstalled apis.ConditionType = "AdditionalPACControllerInstalled"
)

func (pac *OpenShiftPipelinesAsCode) GroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind(KindOpenShiftPipelinesAsCode)
}
Expand Down Expand Up @@ -65,6 +70,10 @@ func (pac *OpenShiftPipelinesAsCodeStatus) MarkInstallerSetReady() {
opacCondSet.Manage(pac).MarkTrue(InstallerSetReady)
}

func (pac *OpenShiftPipelinesAsCodeStatus) MarkAdditionalPACControllerComplete() {
opacCondSet.Manage(pac).MarkTrue(AdditionalPACControllerInstalled)
}

func (pac *OpenShiftPipelinesAsCodeStatus) MarkPostReconcilerComplete() {
opacCondSet.Manage(pac).MarkTrue(PostReconciler)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestOpenShiftPipelinesAsCodeHappyPath(t *testing.T) {
apistest.CheckConditionOngoing(pac, PreReconciler, t)
apistest.CheckConditionOngoing(pac, InstallerSetAvailable, t)
apistest.CheckConditionOngoing(pac, InstallerSetReady, t)
apistest.CheckConditionOngoing(pac, AdditionalPACControllerInstalled, t)
apistest.CheckConditionOngoing(pac, PostReconciler, t)

// Dependencies installed
Expand All @@ -61,10 +62,15 @@ func TestOpenShiftPipelinesAsCodeHappyPath(t *testing.T) {
pac.MarkInstallerSetNotReady("waiting for deployments")
apistest.CheckConditionFailed(pac, InstallerSetReady, t)

// InstallerSet and then PostReconciler become ready and we're good.
// InstallerSet is ready
pac.MarkInstallerSetReady()
apistest.CheckConditionSucceeded(pac, InstallerSetReady, t)

// AdditionalInstallerSet is complete
pac.MarkAdditionalPACControllerComplete()
apistest.CheckConditionSucceeded(pac, AdditionalPACControllerInstalled, t)

// PostReconciler become ready and we're good.
pac.MarkPostReconcilerComplete()
apistest.CheckConditionSucceeded(pac, PostReconciler, t)

Expand All @@ -81,6 +87,7 @@ func TestOpenShiftPipelinesAsCodeErrorPath(t *testing.T) {
apistest.CheckConditionOngoing(pac, PreReconciler, t)
apistest.CheckConditionOngoing(pac, InstallerSetAvailable, t)
apistest.CheckConditionOngoing(pac, InstallerSetReady, t)
apistest.CheckConditionOngoing(pac, AdditionalPACControllerInstalled, t)
apistest.CheckConditionOngoing(pac, PostReconciler, t)

// Dependencies installed
Expand All @@ -99,10 +106,15 @@ func TestOpenShiftPipelinesAsCodeErrorPath(t *testing.T) {
pac.MarkInstallerSetNotReady("waiting for deployments")
apistest.CheckConditionFailed(pac, InstallerSetReady, t)

// InstallerSet and then PostReconciler become ready and we're good.
// InstallerSet is ready
pac.MarkInstallerSetReady()
apistest.CheckConditionSucceeded(pac, InstallerSetReady, t)

// AdditionalInstallerSet is complete
pac.MarkAdditionalPACControllerComplete()
apistest.CheckConditionSucceeded(pac, AdditionalPACControllerInstalled, t)

// PostReconciler become ready and we're good.
pac.MarkPostReconcilerComplete()
apistest.CheckConditionSucceeded(pac, PostReconciler, t)

Expand Down
19 changes: 19 additions & 0 deletions pkg/apis/operator/v1alpha1/openshiftpipelinesascode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ type OpenShiftPipelinesAsCodeList struct {

type PACSettings struct {
Settings map[string]string `json:"settings,omitempty"`
// AdditionalPACControllers allows to deploy additional PAC controller
// +optional
AdditionalPACControllers map[string]AdditionalPACControllerConfig `json:"additionalPACControllers,omitempty"`
// options holds additions fields and these fields will be updated on the manifests
Options AdditionalOptions `json:"options"`
}

// 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"`
// Name of the additional controller Secret
// +optional
SecretName string `json:"secretName,omitempty"`
// Setting will contains the configMap data
// +optional
Settings map[string]string `json:"settings,omitempty"`
}
Loading