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

Migrate ako crd to v1beta1 in akoo #172

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Changes from 1 commit
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
Next Next commit
Update v1beta1 ako crd in akoo
chenlin07 committed Oct 26, 2023
commit 9f2da4af9b4bc98ae7723fb16759f8c410c36c59
21 changes: 11 additions & 10 deletions api/v1alpha1/akodeploymentconfig_webhook.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/pkg/aviclient"
)
@@ -44,46 +45,46 @@ func (r *AKODeploymentConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &AKODeploymentConfig{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *AKODeploymentConfig) ValidateCreate() error {
func (r *AKODeploymentConfig) ValidateCreate() (admission.Warnings, error) {
akoDeploymentConfigLog.Info("validate create", "name", r.Name)

var allErrs field.ErrorList
allErrs = append(allErrs, r.validateClusterSelector(nil)...)
allErrs = append(allErrs, r.validateAVI(nil)...)
if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("AKODeploymentConfig").GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AKODeploymentConfig").GroupKind(), r.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *AKODeploymentConfig) ValidateUpdate(old runtime.Object) error {
func (r *AKODeploymentConfig) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
akoDeploymentConfigLog.Info("validate update", "name", r.Name)
oldADC, ok := old.(*AKODeploymentConfig)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a AKODeploymentConfig but got a %T", old))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a AKODeploymentConfig but got a %T", old))
}
var allErrs field.ErrorList
if oldADC != nil {
allErrs = append(allErrs, r.validateClusterSelector(oldADC)...)
allErrs = append(allErrs, r.validateAVI(oldADC)...)
}
if len(allErrs) == 0 {
return nil
return nil, nil
}
return apierrors.NewInvalid(GroupVersion.WithKind("AKODeploymentConfig").GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("AKODeploymentConfig").GroupKind(), r.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *AKODeploymentConfig) ValidateDelete() error {
func (r *AKODeploymentConfig) ValidateDelete() (admission.Warnings, error) {
akoDeploymentConfigLog.Info("validate delete", "name", r.Name)
// should not delete the akodeploymentconfig selects management cluster
if r.Name == ManagementClusterAkoDeploymentConfig {
return field.Invalid(field.NewPath("spec", "ClusterSelector"),
return nil, field.Invalid(field.NewPath("spec", "ClusterSelector"),
r.Spec.ClusterSelector,
"can't delete akodeploymentconfig object for management cluster")
}
return nil
return nil, nil
}

// validateClusterSelector checks AKODeploymentConfig object's cluster selector field input is valid or not
6 changes: 3 additions & 3 deletions api/v1alpha1/akodeploymentconfig_webhook_test.go
Original file line number Diff line number Diff line change
@@ -373,7 +373,7 @@ func TestCreateNewAKODeploymentConfig(t *testing.T) {
g.Expect(err).ShouldNot(HaveOccurred())
}

err := tc.adc.ValidateCreate()
_, err := tc.adc.ValidateCreate()
if !tc.expectErr {
g.Expect(err).ShouldNot(HaveOccurred())
} else {
@@ -518,7 +518,7 @@ func TestUpdateExistingAKODeploymentConfig(t *testing.T) {
err := kclient.Create(context.Background(), tc.certificateSecret)
g.Expect(err).ShouldNot(HaveOccurred())
}
err := tc.new.ValidateUpdate(tc.old)
_, err := tc.new.ValidateUpdate(tc.old)
if !tc.expectErr {
g.Expect(err).ShouldNot(HaveOccurred())
} else {
@@ -576,7 +576,7 @@ func TestDeleteAKODeploymentConfig(t *testing.T) {
g.Expect(err).ShouldNot(HaveOccurred())
}

err := tc.adc.ValidateDelete()
_, err := tc.adc.ValidateDelete()
if !tc.expectErr {
g.Expect(err).ShouldNot(HaveOccurred())
} else {
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

akoov1alpha1 "github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/api/v1alpha1"
"github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/pkg/aviclient"
@@ -38,11 +37,11 @@ func (r *AKODeploymentConfigReconciler) SetupWithManager(mgr ctrl.Manager) error
return ctrl.NewControllerManagedBy(mgr).
For(&akoov1alpha1.AKODeploymentConfig{}).
Watches(
&source.Kind{Type: &clusterv1.Cluster{}},
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(handlers.AkoDeploymentConfigForCluster(r.Client, r.Log)),
).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.secretToAKODeploymentConfig(r.Client, r.Log)),
).
Complete(r)
@@ -161,8 +160,7 @@ func (r *AKODeploymentConfigReconciler) reconcileDelete(
}

func (r *AKODeploymentConfigReconciler) secretToAKODeploymentConfig(c client.Client, log logr.Logger) handler.MapFunc {
return func(o client.Object) []reconcile.Request {
ctx := context.Background()
return func(ctx context.Context, o client.Object) []reconcile.Request {
secret, ok := o.(*corev1.Secret)
if !ok {
log.Error(errors.New("invalid type"),
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ import (
"github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/pkg/haprovider"

akoov1alpha1 "github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/api/v1alpha1"
akov1alpha1 "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/pkg/apis/ako/v1alpha1"
akov1beta1 "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/pkg/apis/ako/v1beta1"

ako_operator "github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/pkg/ako-operator"
)
@@ -292,7 +292,7 @@ func (r *AKODeploymentConfigReconciler) reconcileAviInfraSetting(
}

newAviInfraSetting := r.createAviInfraSetting(adc)
aviInfraSetting := &akov1alpha1.AviInfraSetting{}
aviInfraSetting := &akov1beta1.AviInfraSetting{}

if err := r.Get(ctx, client.ObjectKey{
Name: haprovider.GetAviInfraSettingName(adc),
@@ -308,37 +308,37 @@ func (r *AKODeploymentConfigReconciler) reconcileAviInfraSetting(
return res, r.Update(ctx, aviInfraSetting)
}

func (r *AKODeploymentConfigReconciler) createAviInfraSetting(adc *akoov1alpha1.AKODeploymentConfig) *akov1alpha1.AviInfraSetting {
func (r *AKODeploymentConfigReconciler) createAviInfraSetting(adc *akoov1alpha1.AKODeploymentConfig) *akov1beta1.AviInfraSetting {
// ShardVSSize describes ingress shared virtual service size, default value is SMALL
shardSize := "SMALL"
if adc.Spec.ExtraConfigs.IngressConfigs.ShardVSSize != "" {
shardSize = adc.Spec.ExtraConfigs.IngressConfigs.ShardVSSize
}

vipNetwork := []akov1alpha1.AviInfraSettingVipNetwork{{
vipNetwork := []akov1beta1.AviInfraSettingVipNetwork{{
NetworkName: adc.Spec.ControlPlaneNetwork.Name,
Cidr: adc.Spec.ControlPlaneNetwork.CIDR,
}}
//Use V6Cidr field if cidr of control plane network is IPv6
if utils.GetIPFamilyFromCidr(adc.Spec.ControlPlaneNetwork.CIDR) == "V6" {
vipNetwork = []akov1alpha1.AviInfraSettingVipNetwork{{
vipNetwork = []akov1beta1.AviInfraSettingVipNetwork{{
NetworkName: adc.Spec.ControlPlaneNetwork.Name,
V6Cidr: adc.Spec.ControlPlaneNetwork.CIDR,
}}
}

return &akov1alpha1.AviInfraSetting{
return &akov1beta1.AviInfraSetting{
ObjectMeta: metav1.ObjectMeta{
Name: haprovider.GetAviInfraSettingName(adc),
},
Spec: akov1alpha1.AviInfraSettingSpec{
SeGroup: akov1alpha1.AviInfraSettingSeGroup{
Spec: akov1beta1.AviInfraSettingSpec{
SeGroup: akov1beta1.AviInfraSettingSeGroup{
Name: adc.Spec.ServiceEngineGroup,
},
Network: akov1alpha1.AviInfraSettingNetwork{
Network: akov1beta1.AviInfraSettingNetwork{
VipNetworks: vipNetwork,
},
L7Settings: akov1alpha1.AviInfraL7Settings{
L7Settings: akov1beta1.AviInfraL7Settings{
ShardSize: shardSize,
},
},
@@ -366,7 +366,7 @@ func (r *AKODeploymentConfigReconciler) reconcileAviInfraSettingDelete(
return res, nil
}

aviInfraSetting := &akov1alpha1.AviInfraSetting{}
aviInfraSetting := &akov1beta1.AviInfraSetting{}
if err := r.Get(ctx, client.ObjectKey{
Name: haprovider.GetAviInfraSettingName(adc),
}, aviInfraSetting); err != nil {
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
"github.com/pkg/errors"
"github.com/vmware/alb-sdk/go/models"
"github.com/vmware/alb-sdk/go/session"
akov1alpha1 "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/pkg/apis/ako/v1alpha1"
akov1beta1 "github.com/vmware/load-balancer-and-ingress-services-for-kubernetes/pkg/apis/ako/v1beta1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -335,7 +335,7 @@ func intgTestAkoDeploymentConfigController() {
aviInfraSettingName = akoDeploymentConfig.Name + "-ais"
ensureRuntimeObjectMatchExpectation(client.ObjectKey{
Name: aviInfraSettingName,
}, &akov1alpha1.AviInfraSetting{}, true)
}, &akov1beta1.AviInfraSetting{}, true)

service := &corev1.Service{}
ensureRuntimeObjectMatchExpectation(client.ObjectKey{
@@ -351,7 +351,7 @@ func intgTestAkoDeploymentConfigController() {
aviInfraSettingName = akoDeploymentConfig.Name + "-ais"
ensureRuntimeObjectMatchExpectation(client.ObjectKey{
Name: aviInfraSettingName,
}, &akov1alpha1.AviInfraSetting{}, true)
}, &akov1beta1.AviInfraSetting{}, true)

service := &corev1.Service{}
ensureRuntimeObjectMatchExpectation(client.ObjectKey{
6 changes: 2 additions & 4 deletions controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ import (
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/go-logr/logr"
"github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/api/v1alpha1"
@@ -37,7 +36,7 @@ func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Watch Cluster resources.
For(&clusterv1.Cluster{}).
Watches(
&source.Kind{Type: &corev1.Service{}},
&corev1.Service{},
handler.EnqueueRequestsFromMapFunc(r.serviceToCluster(r.Client, r.Log)),
).
Complete(r)
@@ -127,8 +126,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
// serviceToCluster returns a handler map function for mapping Service
// resources to the cluster
func (r *ClusterReconciler) serviceToCluster(c client.Client, log logr.Logger) handler.MapFunc {
return func(o client.Object) []reconcile.Request {
ctx := context.Background()
return func(ctx context.Context, o client.Object) []reconcile.Request {
service, ok := o.(*corev1.Service)
if !ok {
log.Error(errors.New("invalid type"),
5 changes: 2 additions & 3 deletions controllers/machine/machine_controller.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ import (
ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// SetupWithManager adds this reconciler to a new controller then to the
@@ -33,7 +32,7 @@ func (r *MachineReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Watch Cluster API Machine resources.
For(&clusterv1.Machine{}).
Watches(
&source.Kind{Type: &clusterv1.Cluster{}},
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(handlers.MachinesForCluster(r.Client, r.Log)),
).
Complete(r)
@@ -76,7 +75,7 @@ func (r *MachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_
}()

// Get the name of the cluster to which the current machine belongs
clusterName, exist := obj.Labels[clusterv1.ClusterLabelName]
clusterName, exist := obj.Labels[clusterv1.ClusterNameLabel]
if !exist {
log.Info("machine doesn't have cluster name label, skip reconciling")
return res, nil
Loading