Skip to content

Commit b9b7e37

Browse files
committed
feat: Remove API Dependency on Tekton and cert-manager
Fixed unit tests: Added CRD establishment wait and Switched to controller-runtime client Updated the e2e test script (hack/run-operator-catalog.sh) to install Tekton and cert-manager before creating the ShipwrightBuild. Signed-off-by: Hasan Awad <hasan.m.awad94@gmail.com>
1 parent 4336047 commit b9b7e37

File tree

5 files changed

+133
-28
lines changed

5 files changed

+133
-28
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ Once OLM has been deployed, use the following command to install the latest oper
1313
$ kubectl apply -f https://operatorhub.io/install/shipwright-operator.yaml
1414
```
1515

16-
## OLM Dependencies
17-
When installed via OLM using the provided Shipwright Operator Bundle, the Shipwright operator will ask OLM to deploy the following operators:
18-
- The [Tekton operator](https://tekton.dev/docs/operator/) to deploy and manage Tekton Pipelines.
19-
- The [Cert-Manager operator](https://cert-manager.io/docs/installation/operator-lifecycle-manager/) to provision certificates for admission/conversion webhooks.
20-
For this to work, the Shipwright operator must be included in a catalog that includes these other operators.
16+
## Prerequisites
17+
18+
Before installing the Shipwright operator, you must have the following components installed in your cluster:
19+
20+
- **Tekton**: The Shipwright operator requires Tekton Pipelines to be installed. Follow the [Tekton installation instructions](https://tekton.dev/docs/setup/) to install Tekton in your cluster.
21+
- **cert-manager**: The Shipwright operator uses cert-manager to provision certificates for admission/conversion webhooks. Follow the [cert-manager installation instructions](https://cert-manager.io/docs/installation/) to install cert-manager in your cluster.
22+
23+
**Note**: The cert-manager operator has been deprecated. Please install cert-manager directly using the recommended installation method from the [cert-manager documentation](https://cert-manager.io/docs/installation/).
2124

2225
## Usage
2326

bundle/manifests/shipwright-operator.clusterserviceversion.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,17 @@ spec:
3636
kind: ShipwrightBuild
3737
name: shipwrightbuilds.operator.shipwright.io
3838
version: v1alpha1
39-
required:
40-
- kind: TektonConfig
41-
name: tektonconfigs.operator.tekton.dev
42-
version: v1alpha1
43-
- kind: Certificate
44-
name: certificates.cert-manager.io
45-
version: v1
4639
description: |
4740
Shipwright is a framework for building container images on Kubernetes.
4841
4942
Read more: [https://shipwright.io](https://shipwright.io)
5043
44+
## Prerequisites
45+
46+
Before installing the Shipwright operator, ensure the following components are installed:
47+
- **Tekton**: Follow the [Tekton installation instructions](https://tekton.dev/docs/setup/) to install Tekton Pipelines.
48+
- **cert-manager**: Follow the [cert-manager installation instructions](https://cert-manager.io/docs/installation/) to install cert-manager for webhook certificate provisioning.
49+
5150
## Usage
5251
5352
To deploy and manage [Shipwright Builds](https://github.com/shipwright-io/build) in your cluster,

config/manifests/bases/shipwright-operator.clusterserviceversion.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ spec:
2222
kind: ShipwrightBuild
2323
name: shipwrightbuilds.operator.shipwright.io
2424
version: v1alpha1
25-
required:
26-
- kind: TektonConfig
27-
name: tektonconfigs.operator.tekton.dev
28-
version: v1alpha1
29-
- kind: Certificate
30-
name: certificates.cert-manager.io
31-
version: v1
3225
description: |
3326
Shipwright is a framework for building container images on Kubernetes.
3427
3528
Read more: [https://shipwright.io](https://shipwright.io)
3629
30+
## Prerequisites
31+
32+
Before installing the Shipwright operator, ensure the following components are installed:
33+
- **Tekton**: Follow the [Tekton installation instructions](https://tekton.dev/docs/setup/) to install Tekton Pipelines.
34+
- **cert-manager**: Follow the [cert-manager installation instructions](https://cert-manager.io/docs/installation/) to install cert-manager for webhook certificate provisioning.
35+
3736
## Usage
3837
3938
To deploy and manage [Shipwright Builds](https://github.com/shipwright-io/build) in your cluster,

controllers/suite_test.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ func setupTektonCRDs(ctx context.Context) {
126126
tektonOpCRD.Status.StoredVersions = []string{"v1alpha1"}
127127
err = k8sClient.Create(ctx, tektonOpCRD, &client.CreateOptions{})
128128
Expect(err).NotTo(HaveOccurred())
129+
130+
// Wait for the CRD to be established before proceeding
131+
Eventually(func() bool {
132+
crd := &crdv1.CustomResourceDefinition{}
133+
if err := k8sClient.Get(ctx, types.NamespacedName{Name: "tektonconfigs.operator.tekton.dev"}, crd); err != nil {
134+
return false
135+
}
136+
for _, condition := range crd.Status.Conditions {
137+
if condition.Type == crdv1.Established && condition.Status == crdv1.ConditionTrue {
138+
return true
139+
}
140+
}
141+
return false
142+
}).Should(BeTrue(), "TektonConfig CRD should be established")
129143
}
130144
Expect(err).NotTo(HaveOccurred())
131145
}
@@ -191,31 +205,39 @@ func createTektonConfig(ctx context.Context) *tektonoperatorv1alpha1.TektonConfi
191205
},
192206
},
193207
}
194-
_, err := tektonOpClient.TektonConfigs().Create(ctx, tektonConfig, metav1.CreateOptions{})
208+
// Use controller-runtime client instead of REST client for better compatibility with envtest
209+
err := k8sClient.Create(ctx, tektonConfig, &client.CreateOptions{})
195210
if errors.IsAlreadyExists(err) {
196-
// If it already exists, that's fine
197-
err = nil
211+
// If it already exists, fetch it
212+
err = k8sClient.Get(ctx, types.NamespacedName{Name: "config"}, tektonConfig)
213+
Expect(err).NotTo(HaveOccurred())
214+
} else {
215+
Expect(err).NotTo(HaveOccurred())
198216
}
199-
Expect(err).To(BeNil())
200217

201218
return tektonConfig
202219
}
203220

204221
// deleteTektonConfig tears down the given TektonConfig instance.
205222
func deleteTektonConfig(ctx context.Context) {
206223
By("deleting the TektonConfig instance")
207-
err := tektonOpClient.TektonConfigs().Delete(ctx, "config", metav1.DeleteOptions{})
224+
tektonConfig := &tektonoperatorv1alpha1.TektonConfig{
225+
ObjectMeta: metav1.ObjectMeta{
226+
Name: "config",
227+
},
228+
}
229+
err := k8sClient.Delete(ctx, tektonConfig, &client.DeleteOptions{})
208230
// the delete e2e's can delete this object before this AfterEach runs
209231
if errors.IsNotFound(err) {
210232
return
211233
}
212234
Expect(err).NotTo(HaveOccurred())
213235

214236
By("waiting for TektonConfig instance to be completely removed")
215-
Eventually(func() error {
216-
_, err := tektonOpClient.TektonConfigs().Get(ctx, "config", metav1.GetOptions{})
217-
return err
218-
}, "30s", "5s").Should(WithTransform(errors.IsNotFound, BeTrue()))
237+
Eventually(func() bool {
238+
err := k8sClient.Get(ctx, types.NamespacedName{Name: "config"}, tektonConfig)
239+
return errors.IsNotFound(err)
240+
}, "30s", "5s").Should(BeTrue(), "TektonConfig should be deleted")
219241
}
220242

221243
var _ = BeforeSuite(func() {

hack/run-operator-catalog.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# - SUBSCRIPTION_NAMESPACE: Namespace to install the operator via an OLM subscription. Defaults to
1818
# shipwright-operator.
1919
# - NAME_PREFIX: prefix to use for all resource names. Defaults to "shipwright-"
20+
# - TEKTON_OPERATOR_VERSION: Tekton Operator version to install. Defaults to v0.77.0 (matches go.mod).
21+
# - CERT_MANAGER_VERSION: cert-manager version to install. Defaults to v1.13.0.
2022

2123
set -eu -o pipefail
2224

@@ -81,6 +83,82 @@ function wait_for_pod() {
8183
${KUBECTL_BIN} wait --for=condition=Ready pod -l "${label}" -n "${namespace}" --timeout "${timeout}"
8284
}
8385

86+
function install_tekton() {
87+
echo "Installing Tekton Operator"
88+
# Install Tekton Operator using the official installation method (https://github.com/tektoncd/operator/releases)
89+
# Minimum supported version is v0.50.0 (see pkg/common/const.go)
90+
# Default version matches the dependency in go.mod (v0.77.0) for stability
91+
# Can be overridden via TEKTON_OPERATOR_VERSION env var
92+
TEKTON_OPERATOR_VERSION=${TEKTON_OPERATOR_VERSION:-v0.77.0}
93+
echo "Installing Tekton Operator version ${TEKTON_OPERATOR_VERSION}"
94+
if ! ${KUBECTL_BIN} apply -f "https://storage.googleapis.com/tekton-releases/operator/previous/${TEKTON_OPERATOR_VERSION}/release.yaml"; then
95+
echo "Warning: Failed to install Tekton Operator ${TEKTON_OPERATOR_VERSION}, falling back to latest"
96+
${KUBECTL_BIN} apply -f "https://storage.googleapis.com/tekton-releases/operator/latest/release.yaml"
97+
fi
98+
99+
echo "Waiting for Tekton Operator to be ready"
100+
# Wait for the operator namespace to exist first
101+
for i in {1..30}; do
102+
if ${KUBECTL_BIN} get namespace tekton-operator &>/dev/null; then
103+
break
104+
fi
105+
sleep 2
106+
done
107+
108+
if ! wait_for_pod "app=tekton-operator" "tekton-operator" 5m; then
109+
echo "Failed to deploy Tekton Operator"
110+
${KUBECTL_BIN} get pods -n tekton-operator
111+
exit 1
112+
fi
113+
114+
echo "Creating TektonConfig instance"
115+
${KUBECTL_BIN} apply -f - <<EOF
116+
apiVersion: operator.tekton.dev/v1alpha1
117+
kind: TektonConfig
118+
metadata:
119+
name: config
120+
spec:
121+
profile: lite
122+
targetNamespace: tekton-pipelines
123+
EOF
124+
125+
echo "Waiting for TektonConfig to be ready"
126+
if ! ${KUBECTL_BIN} wait --for=condition=Ready tektonconfigs.operator.tekton.dev/config --timeout=5m; then
127+
echo "Failed to deploy TektonConfig"
128+
${KUBECTL_BIN} get tektonconfigs -o yaml
129+
${KUBECTL_BIN} get tektonconfigs config -o yaml
130+
exit 1
131+
fi
132+
}
133+
134+
function install_cert_manager() {
135+
echo "Installing cert-manager"
136+
# Install cert-manager using the official installation method (https://github.com/cert-manager/cert-manager/releases)
137+
# Default version is v1.13.0 (stable release)
138+
# Can be overridden via CERT_MANAGER_VERSION env var
139+
CERT_MANAGER_VERSION=${CERT_MANAGER_VERSION:-v1.13.0}
140+
echo "Installing cert-manager version ${CERT_MANAGER_VERSION}"
141+
${KUBECTL_BIN} apply -f "https://github.com/cert-manager/cert-manager/releases/download/${CERT_MANAGER_VERSION}/cert-manager.yaml"
142+
143+
echo "Waiting for cert-manager pods to be ready"
144+
if ! wait_for_pod "app.kubernetes.io/instance=cert-manager" "cert-manager" 5m; then
145+
echo "Failed to deploy cert-manager"
146+
${KUBECTL_BIN} get pods -n cert-manager
147+
exit 1
148+
fi
149+
150+
echo "Waiting for cert-manager webhook to be ready"
151+
# Wait for the webhook to be ready by checking if it can validate certificates
152+
for i in {1..30}; do
153+
if ${KUBECTL_BIN} get validatingwebhookconfigurations cert-manager-webhook &>/dev/null; then
154+
echo "cert-manager webhook is ready"
155+
return 0
156+
fi
157+
sleep 2
158+
done
159+
echo "Warning: cert-manager webhook may not be fully ready, continuing anyway"
160+
}
161+
84162
add_kustomizations
85163

86164
echo "Deploying catalog source"
@@ -108,6 +186,10 @@ if ! wait_for_pod "app=shipwright-operator" "${SUBSCRIPTION_NAMESPACE}" 5m; then
108186
exit 1
109187
fi
110188

189+
echo "Installing prerequisites"
190+
install_cert_manager
191+
install_tekton
192+
111193
echo "Deploying Shipwright build controller"
112194

113195
${KUBECTL_BIN} apply -f - <<EOF

0 commit comments

Comments
 (0)