@@ -14,19 +14,21 @@ import (
1414
1515 . "github.com/onsi/ginkgo/v2"
1616 . "github.com/onsi/gomega"
17-
17+ corev1 "k8s.io/api/core/v1"
1818 crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1919 crdclientv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
2020 "k8s.io/apimachinery/pkg/api/errors"
2121 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222 "k8s.io/apimachinery/pkg/types"
2323 "k8s.io/client-go/kubernetes/scheme"
24+ duckv1 "knative.dev/pkg/apis/duck/v1"
2425 ctrl "sigs.k8s.io/controller-runtime"
2526 "sigs.k8s.io/controller-runtime/pkg/client"
2627 "sigs.k8s.io/controller-runtime/pkg/envtest"
2728 logf "sigs.k8s.io/controller-runtime/pkg/log"
2829 "sigs.k8s.io/controller-runtime/pkg/log/zap"
2930
31+ tektonoperatorv1alpha1 "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1"
3032 tektonoperatorv1alpha1client "github.com/tektoncd/operator/pkg/client/clientset/versioned/typed/operator/v1alpha1"
3133
3234 buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1"
@@ -40,12 +42,13 @@ import (
4042// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
4143
4244var (
43- k8sClient client.Client
44- ctx context.Context
45- cancel context.CancelFunc
46- testEnv * envtest.Environment
47- restTimeout = 5 * time .Second
48- restRetry = 100 * time .Millisecond
45+ k8sClient client.Client
46+ ctx context.Context
47+ cancel context.CancelFunc
48+ testEnv * envtest.Environment
49+ restTimeout = 5 * time .Second
50+ restRetry = 100 * time .Millisecond
51+ tektonOpClient tektonoperatorv1alpha1client.OperatorV1alpha1Interface
4952)
5053
5154func TestAPIs (t * testing.T ) {
@@ -75,6 +78,7 @@ func setupTektonCRDs(ctx context.Context) {
7578 {
7679 Name : "v1beta1" ,
7780 Storage : true ,
81+ Served : true ,
7882 Schema : & crdv1.CustomResourceValidation {
7983 OpenAPIV3Schema : & crdv1.JSONSchemaProps {
8084 Type : "object" ,
@@ -106,6 +110,7 @@ func setupTektonCRDs(ctx context.Context) {
106110 {
107111 Name : "v1alpha1" ,
108112 Storage : true ,
113+ Served : true ,
109114 Schema : & crdv1.CustomResourceValidation {
110115 OpenAPIV3Schema : & crdv1.JSONSchemaProps {
111116 Type : "object" ,
@@ -168,6 +173,51 @@ func deleteShipwrightBuild(ctx context.Context, build *operatorv1alpha1.Shipwrig
168173 test .EventuallyRemoved (ctx , k8sClient , build )
169174}
170175
176+ // createTektonConfig creates a TektonConfig instance with ready status
177+ func createTektonConfig (ctx context.Context ) * tektonoperatorv1alpha1.TektonConfig {
178+ By ("creating TektonConfig instance" )
179+ tektonConfig := & tektonoperatorv1alpha1.TektonConfig {
180+ ObjectMeta : metav1.ObjectMeta {
181+ Name : "config" ,
182+ },
183+ Status : tektonoperatorv1alpha1.TektonConfigStatus {
184+ Status : duckv1.Status {
185+ Conditions : duckv1.Conditions {
186+ {
187+ Type : ConditionReady ,
188+ Status : corev1 .ConditionTrue ,
189+ },
190+ },
191+ },
192+ },
193+ }
194+ _ , err := tektonOpClient .TektonConfigs ().Create (ctx , tektonConfig , metav1.CreateOptions {})
195+ if errors .IsAlreadyExists (err ) {
196+ // If it already exists, that's fine
197+ err = nil
198+ }
199+ Expect (err ).To (BeNil ())
200+
201+ return tektonConfig
202+ }
203+
204+ // deleteTektonConfig tears down the given TektonConfig instance.
205+ func deleteTektonConfig (ctx context.Context ) {
206+ By ("deleting the TektonConfig instance" )
207+ err := tektonOpClient .TektonConfigs ().Delete (ctx , "config" , metav1.DeleteOptions {})
208+ // the delete e2e's can delete this object before this AfterEach runs
209+ if errors .IsNotFound (err ) {
210+ return
211+ }
212+ Expect (err ).NotTo (HaveOccurred ())
213+
214+ 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 ()))
219+ }
220+
171221var _ = BeforeSuite (func () {
172222 logf .SetLogger (zap .New (zap .WriteTo (GinkgoWriter ), zap .UseDevMode (true )))
173223
@@ -190,7 +240,8 @@ var _ = BeforeSuite(func() {
190240 err = buildv1beta1 .AddToScheme (scheme .Scheme )
191241 Expect (err ).NotTo (HaveOccurred ())
192242
193- // +kubebuilder:scaffold:scheme
243+ err = tektonoperatorv1alpha1 .AddToScheme (scheme .Scheme )
244+ Expect (err ).NotTo (HaveOccurred ())
194245
195246 mgr , err := ctrl .NewManager (cfg , ctrl.Options {
196247 Scheme : scheme .Scheme ,
@@ -200,6 +251,7 @@ var _ = BeforeSuite(func() {
200251 Expect (err ).NotTo (HaveOccurred ())
201252 toClient , err := tektonoperatorv1alpha1client .NewForConfig (mgr .GetConfig ())
202253 Expect (err ).NotTo (HaveOccurred ())
254+ tektonOpClient = toClient
203255 err = (& ShipwrightBuildReconciler {
204256 CRDClient : crdClient ,
205257 TektonOperatorClient : toClient ,
0 commit comments