From 415904bc117c4bbcf7a9590a8ea14b1ae0a232e6 Mon Sep 17 00:00:00 2001 From: Jawed khelil Date: Mon, 7 Aug 2023 16:47:23 +0200 Subject: [PATCH] migrate to ai v1beta1 --- api/v1beta1/zz_generated.deepcopy.go | 10 +++++++++- controllers/default_test.go | 8 ++++---- controllers/shipwrightbuild_controller.go | 10 +++++----- controllers/shipwrightbuild_controller_test.go | 12 ++++++------ controllers/suite_test.go | 4 ++-- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 2d35595b..059fd2b8 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -10,6 +10,7 @@ package v1beta1 import ( + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -19,7 +20,7 @@ func (in *ShipwrightBuild) DeepCopyInto(out *ShipwrightBuild) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Spec = in.Spec - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShipwrightBuild. @@ -90,6 +91,13 @@ func (in *ShipwrightBuildSpec) DeepCopy() *ShipwrightBuildSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ShipwrightBuildStatus) DeepCopyInto(out *ShipwrightBuildStatus) { *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]v1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ShipwrightBuildStatus. diff --git a/controllers/default_test.go b/controllers/default_test.go index caaa8275..5cef8251 100644 --- a/controllers/default_test.go +++ b/controllers/default_test.go @@ -13,7 +13,7 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/shipwright-io/operator/api/v1alpha1" + "github.com/shipwright-io/operator/api/v1beta1" "github.com/shipwright-io/operator/test" ) @@ -34,7 +34,7 @@ var _ = g.Describe("Reconcile default ShipwrightBuild installation", func() { // targetNamespace namespace where shipwright Controller and dependencies will be located const targetNamespace = "target-namespace" // build Build instance employed during testing - var build *v1alpha1.ShipwrightBuild + var build *v1beta1.ShipwrightBuild baseClusterRole := &rbacv1.ClusterRole{ ObjectMeta: metav1.ObjectMeta{ @@ -126,12 +126,12 @@ var _ = g.Describe("Reconcile default ShipwrightBuild installation", func() { o.Expect(err).NotTo(o.HaveOccurred()) g.By("creating a ShipwrightBuild instance") - build = &v1alpha1.ShipwrightBuild{ + build = &v1beta1.ShipwrightBuild{ ObjectMeta: metav1.ObjectMeta{ Namespace: namespace, Name: "cluster", }, - Spec: v1alpha1.ShipwrightBuildSpec{ + Spec: v1beta1.ShipwrightBuildSpec{ TargetNamespace: targetNamespace, }, } diff --git a/controllers/shipwrightbuild_controller.go b/controllers/shipwrightbuild_controller.go index 98732c2f..028ef6c4 100644 --- a/controllers/shipwrightbuild_controller.go +++ b/controllers/shipwrightbuild_controller.go @@ -27,7 +27,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" - "github.com/shipwright-io/operator/api/v1alpha1" + "github.com/shipwright-io/operator/api/v1beta1" "github.com/shipwright-io/operator/pkg/tekton" ) @@ -54,7 +54,7 @@ type ShipwrightBuildReconciler struct { } // setFinalizer append finalizer on the resource, and uses local client to update it immediately. -func (r *ShipwrightBuildReconciler) setFinalizer(ctx context.Context, b *v1alpha1.ShipwrightBuild) error { +func (r *ShipwrightBuildReconciler) setFinalizer(ctx context.Context, b *v1beta1.ShipwrightBuild) error { if contains(b.GetFinalizers(), FinalizerAnnotation) { return nil } @@ -63,7 +63,7 @@ func (r *ShipwrightBuildReconciler) setFinalizer(ctx context.Context, b *v1alpha } // unsetFinalizer remove all instances of local finalizer string, updating the resource immediately. -func (r *ShipwrightBuildReconciler) unsetFinalizer(ctx context.Context, b *v1alpha1.ShipwrightBuild) error { +func (r *ShipwrightBuildReconciler) unsetFinalizer(ctx context.Context, b *v1beta1.ShipwrightBuild) error { finalizers := []string{} for _, f := range b.GetFinalizers() { if f == FinalizerAnnotation { @@ -90,7 +90,7 @@ func (r *ShipwrightBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ return Requeue() } // retrieving the ShipwrightBuild instance requested for reconcile - b := &v1alpha1.ShipwrightBuild{} + b := &v1beta1.ShipwrightBuild{} if err := r.Get(ctx, req.NamespacedName, b); err != nil { if errors.IsNotFound(err) { logger.Info("Resource is not found!") @@ -236,7 +236,7 @@ func (r *ShipwrightBuildReconciler) SetupWithManager(mgr ctrl.Manager) error { return err } return ctrl.NewControllerManagedBy(mgr). - For(&v1alpha1.ShipwrightBuild{}, builder.WithPredicates(predicate.Funcs{ + For(&v1beta1.ShipwrightBuild{}, builder.WithPredicates(predicate.Funcs{ CreateFunc: func(ce event.CreateEvent) bool { // all new objects must be subject to reconciliation return true diff --git a/controllers/shipwrightbuild_controller_test.go b/controllers/shipwrightbuild_controller_test.go index eea9bb1f..e82d9874 100644 --- a/controllers/shipwrightbuild_controller_test.go +++ b/controllers/shipwrightbuild_controller_test.go @@ -21,7 +21,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "github.com/shipwright-io/operator/api/v1alpha1" + "github.com/shipwright-io/operator/api/v1beta1" tektonoperatorv1alpha1 "github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" tektonoperatorv1alpha1client "github.com/tektoncd/operator/pkg/client/clientset/versioned/fake" crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" @@ -31,7 +31,7 @@ import ( // ready to interact with Manifestival, returning the Manifestival instance and the client. func bootstrapShipwrightBuildReconciler( t *testing.T, - b *v1alpha1.ShipwrightBuild, + b *v1beta1.ShipwrightBuild, tcfg *tektonoperatorv1alpha1.TektonConfig, tcrds []*crdv1.CustomResourceDefinition, ) (client.Client, *crdclientv1.Clientset, *tektonoperatorv1alpha1client.Clientset, *ShipwrightBuildReconciler) { @@ -40,7 +40,7 @@ func bootstrapShipwrightBuildReconciler( s := runtime.NewScheme() s.AddKnownTypes(corev1.SchemeGroupVersion, &corev1.Namespace{}) s.AddKnownTypes(appsv1.SchemeGroupVersion, &appsv1.Deployment{}) - s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.ShipwrightBuild{}) + s.AddKnownTypes(v1beta1.GroupVersion, &v1beta1.ShipwrightBuild{}) logger := zap.New() @@ -91,7 +91,7 @@ func bootstrapShipwrightBuildReconciler( func TestShipwrightBuildReconciler_Finalizers(t *testing.T) { g := o.NewGomegaWithT(t) - b := &v1alpha1.ShipwrightBuild{ObjectMeta: metav1.ObjectMeta{Name: "name", Namespace: "default"}} + b := &v1beta1.ShipwrightBuild{ObjectMeta: metav1.ObjectMeta{Name: "name", Namespace: "default"}} _, _, _, r := bootstrapShipwrightBuildReconciler(t, b, &tektonoperatorv1alpha1.TektonConfig{}, []*crdv1.CustomResourceDefinition{}) // adding one entry on finalizers slice, making sure it's registered @@ -123,12 +123,12 @@ func testShipwrightBuildReconcilerReconcile(t *testing.T, targetNamespace string } req := reconcile.Request{NamespacedName: namespacedName} - b := &v1alpha1.ShipwrightBuild{ + b := &v1beta1.ShipwrightBuild{ ObjectMeta: metav1.ObjectMeta{ Name: namespacedName.Name, Namespace: namespacedName.Namespace, }, - Spec: v1alpha1.ShipwrightBuildSpec{ + Spec: v1beta1.ShipwrightBuildSpec{ TargetNamespace: targetNamespace, }, } diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 0d5bbbee..17dbf944 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -25,7 +25,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - operatorv1alpha1 "github.com/shipwright-io/operator/api/v1alpha1" + operatorv1beta1 "github.com/shipwright-io/operator/api/v1beta1" // +kubebuilder:scaffold:imports ) @@ -65,7 +65,7 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) - err = operatorv1alpha1.AddToScheme(scheme.Scheme) + err = operatorv1beta1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) err = apiextv1.AddToScheme(scheme.Scheme)