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

deploy shipwright triggers via operator #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ Refer to the [ShipwrightBuild documentation](docs/shipwrightbuild.md) for more i

The operator handles differents environment variables to customize Shiprwright controller installation:
KO_DATA_PATH : defines the shipwright controller manifest to install
INSTALL_TRIGGERS: if set to true the operator will install Shipwright Triggers
IMAGE_SHIPWRIGHT_SHIPWRIGHT_BUILD : defines the Shipwright Build Controller Image to use
IMAGE_SHIPWRIGHT_GIT_CONTAINER_IMAGE: defines the Shipwright Git Container Image to use
IMAGE_SHIPWRIGHT_MUTATE_IMAGE_CONTAINER_IMAGE: defines the Shipwright Mutate Image to use
IMAGE_SHIPWRIGHT_BUNDLE_CONTAINER_IMAGE: defines the Shipwright Bundle Image to use
IMAGE_SHIPWRIGHT_WAITER_CONTAINER_IMAGE: defines the Shipwright Waiter Image to use
IMAGE_SHIPWRIGHT_SHIPWRIGHT_TRIGGERS: defines the Shipwright Triggers Image to use

## Contributing

Expand Down
32 changes: 32 additions & 0 deletions bundle/manifests/shipwright-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,38 @@ spec:
- get
- patch
- update
- apiGroups:
- operator.tekton.dev
resources:
- customruns
verbs:
- get
- list
- watch
- apiGroups:
- operator.tekton.dev
resources:
- customruns/finalizers
verbs:
- patch
- update
- apiGroups:
- operator.tekton.dev
resources:
- customruns/status
verbs:
- patch
- update
- apiGroups:
- operator.tekton.dev
resources:
- pipelineruns
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- operator.tekton.dev
resources:
Expand Down
32 changes: 32 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ rules:
- get
- patch
- update
- apiGroups:
- operator.tekton.dev
resources:
- customruns
verbs:
- get
- list
- watch
- apiGroups:
- operator.tekton.dev
resources:
- customruns/finalizers
verbs:
- patch
- update
- apiGroups:
- operator.tekton.dev
resources:
- customruns/status
verbs:
- patch
- update
- apiGroups:
- operator.tekton.dev
resources:
- pipelineruns
verbs:
- get
- list
- patch
- update
- watch
- apiGroups:
- operator.tekton.dev
resources:
Expand Down
10 changes: 10 additions & 0 deletions controllers/shipwrightbuild_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,23 @@ func (r *ShipwrightBuildReconciler) setupManifestival(managerLogger logr.Logger)
if err != nil {
return err
}

buildManifest := filepath.Join(dataPath, "release.yaml")

r.Manifest, err = manifestival.NewManifest(
buildManifest,
manifestival.UseClient(client),
manifestival.UseLogger(logger),
)

if withTriggers() {
triggersManifest := filepath.Join(dataPath, "triggers.yaml")
m, err := manifestival.ManifestFrom(manifestival.Recursive(triggersManifest))
if err != nil {
return err
}
r.Manifest = r.Manifest.Append(m)
}
return err
}

Expand Down
1 change: 1 addition & 0 deletions controllers/shipwrightbuild_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func testShipwrightBuildReconcilerReconcile(t *testing.T, targetNamespace string
{"IMAGE_SHIPWRIGHT_WAITER_CONTAINER_IMAGE", "ghcr.io/shipwright-io/build/waiter:nightly-2023-05-05-1683263383"},
{"IMAGE_SHIPWRIGHT_MUTATE_IMAGE_CONTAINER_IMAGE", "ghcr.io/shipwright-io/build/mutate-image:nightly-2023-04-18-1681794585"},
{"IMAGE_SHIPWRIGHT_BUNDLE_CONTAINER_IMAGE", "ghcr.io/shipwright-io/build/bundle:nightly-2023-05-05-1683263383"},
{"IMAGE_SHIPWRIGHT_SHIPWRIGHT_TRIGGERS", "quay.io/jkhelil/openshift-builds-triggers"},
}

t.Logf("Deploying Shipwright Controller against '%s' namespace", targetNamespace)
Expand Down
4 changes: 4 additions & 0 deletions controllers/shipwrightbuild_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ package controllers
// +kubebuilder:rbac:groups=operator.shipwright.io,resources=shipwrightbuilds/finalizers,verbs=update
// +kubebuilder:rbac:groups=operator.shipwright.io,resources=shipwrightbuilds/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=operator.tekton.dev,resources=tektonconfigs,verbs=get;list;create
// +kubebuilder:rbac:groups=operator.tekton.dev,resources=customruns,verbs=get;list;watch
// +kubebuilder:rbac:groups=operator.tekton.dev,resources=customruns/finalizers,verbs=patch;update
// +kubebuilder:rbac:groups=operator.tekton.dev,resources=customruns/status,verbs=patch;update
// +kubebuilder:rbac:groups=operator.tekton.dev,resources=pipelineruns,verbs=get;list;patch;update;watch
5 changes: 5 additions & 0 deletions controllers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// koDataPathEnv ko data-path environment variable.
const (
koDataPathEnv = "KO_DATA_PATH"
InstallTriggers = "INSTALL_TRIGGERS"
ShipwrightImagePrefix = "IMAGE_SHIPWRIGHT_"
)

Expand Down Expand Up @@ -117,3 +118,7 @@ func replaceContainersEnvImage(container corev1.Container, images map[string]str
}
}
}

func withTriggers() bool {
return os.Getenv(InstallTriggers) == "true"
}
214 changes: 214 additions & 0 deletions kodata/triggers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: shipwright-build
name: shipwright-triggers
labels:
app.kubernetes.io/name: shipwright-triggers
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: shipwright-triggers
name: shipwright-triggers
rules:
- apiGroups:
- shipwright.io
resources:
- buildruns
verbs:
- create
- get
- list
- update
- watch
- apiGroups:
- shipwright.io
resources:
- builds
verbs:
- get
- list
- watch
- apiGroups:
- tekton.dev
resources:
- customruns
verbs:
- get
- list
- watch
- apiGroups:
- tekton.dev
resources:
- customruns/finalizers
verbs:
- patch
- update
- apiGroups:
- tekton.dev
resources:
- customruns/status
verbs:
- patch
- update
- apiGroups:
- tekton.dev
resources:
- pipelineruns
verbs:
- get
- list
- patch
- update
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: shipwright-triggers
labels:
app.kubernetes.io/name: shipwright-triggers
subjects:
- kind: ServiceAccount
namespace: shipwright-build
name: shipwright-triggers
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: shipwright-triggers
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: shipwright-build
labels:
app.kubernetes.io/name: shipwright-triggers
name: shipwright-triggers
rules:
- apiGroups:
- shipwright.io
resources:
- buildruns
verbs:
- create
- get
- list
- update
- watch
- apiGroups:
- shipwright.io
resources:
- builds
verbs:
- get
- list
- watch
- apiGroups:
- tekton.dev
resources:
- customruns
verbs:
- get
- list
- watch
- apiGroups:
- tekton.dev
resources:
- customruns/finalizers
verbs:
- patch
- update
- apiGroups:
- tekton.dev
resources:
- customruns/status
verbs:
- patch
- update
- apiGroups:
- tekton.dev
resources:
- pipelineruns
verbs:
- get
- list
- patch
- update
- watch
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: shipwright-build
name: shipwright-triggers
labels:
app.kubernetes.io/name: shipwright-triggers
subjects:
- kind: ServiceAccount
namespace: shipwright-build
name: shipwright-triggers
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: shipwright-triggers
---
apiVersion: v1
kind: Service
metadata:
namespace: shipwright-build
name: shipwright-triggers
labels:
app.kubernetes.io/name: shipwright-triggers
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: shipwright-triggers
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: shipwright-build
name: shipwright-triggers
labels:
app.kubernetes.io/name: shipwright-triggers
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: shipwright-triggers
template:
metadata:
labels:
app.kubernetes.io/name: shipwright-triggers
spec:
serviceAccountName: shipwright-triggers
containers:
- name: shipwright-triggers
image: "quay.io/jkhelil/openshift-builds-triggers:latest"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use official image from shipwright.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the official image is not publsihed, lets wait for it to be published then, I will update it

args:
- --health-probe-bind-address
- ":8081"
imagePullPolicy: IfNotPresent
ports:
- name: webhook
containerPort: 80
protocol: TCP
- name: probe
containerPort: 8081
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
port: probe
readinessProbe:
httpGet:
path: /readyz
port: probe