Skip to content

Commit

Permalink
use patch to avoid auto fill default value
Browse files Browse the repository at this point in the history
Signed-off-by: Xudong Liu <[email protected]>
  • Loading branch information
XudongLiuHarold committed Oct 24, 2023
1 parent ccdd264 commit aa3f3ac
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"bytes"
"context"
"errors"
"github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/pkg/utils"
"sync"

"github.com/vmware-tanzu/load-balancer-operator-for-kubernetes/pkg/utils"

"net"
"sort"

Expand All @@ -19,6 +20,8 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -290,25 +293,24 @@ func (r *AKODeploymentConfigReconciler) reconcileAviInfraSetting(
log.Info("ControlPlaneNetwork is empty in akoDeploymentConfig, skip creating AVIInfraSetting")
return res, nil
}
return res, r.Patch(ctx, r.createAviInfraSetting(adc), client.Apply, client.ForceOwnership, client.FieldOwner("field-owner"))
}

newAviInfraSetting := r.createAviInfraSetting(adc)
aviInfraSetting := &akov1beta1.AviInfraSetting{}
// AviInfraSetting is a top-level type
type AviInfraSetting struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec AviInfraSettingSpec `json:"spec,omitempty"`
}

if err := r.Get(ctx, client.ObjectKey{
Name: haprovider.GetAviInfraSettingName(adc),
}, aviInfraSetting); err != nil {
if apierrors.IsNotFound(err) {
log.Info("AVIInfraSetting doesn't exist, start creating it")
return res, r.Create(ctx, newAviInfraSetting)
}
log.Error(err, "Failed to get AVIInfraSetting, requeue")
return res, err
}
newAviInfraSetting.Spec.DeepCopyInto(&aviInfraSetting.Spec)
return res, r.Update(ctx, aviInfraSetting)
type AviInfraSettingSpec struct {
Network akov1beta1.AviInfraSettingNetwork `json:"network,omitempty"`
SeGroup akov1beta1.AviInfraSettingSeGroup `json:"seGroup,omitempty"`
L7Settings akov1beta1.AviInfraL7Settings `json:"l7Settings,omitempty"`
NSXSettings *akov1beta1.AviInfraNSXSettings `json:"nsxSettings,omitempty"`
}

func (r *AKODeploymentConfigReconciler) createAviInfraSetting(adc *akoov1alpha1.AKODeploymentConfig) *akov1beta1.AviInfraSetting {
func (r *AKODeploymentConfigReconciler) createAviInfraSetting(adc *akoov1alpha1.AKODeploymentConfig) *unstructured.Unstructured {
// ShardVSSize describes ingress shared virtual service size, default value is SMALL
shardSize := "SMALL"
if adc.Spec.ExtraConfigs.IngressConfigs.ShardVSSize != "" {
Expand All @@ -327,11 +329,15 @@ func (r *AKODeploymentConfigReconciler) createAviInfraSetting(adc *akoov1alpha1.
}}
}

return &akov1beta1.AviInfraSetting{
aviinfraSetting := &AviInfraSetting{
TypeMeta: metav1.TypeMeta{
APIVersion: "ako.vmware.com/v1beta1",
Kind: "AviInfraSetting",
},
ObjectMeta: metav1.ObjectMeta{
Name: haprovider.GetAviInfraSettingName(adc),
},
Spec: akov1beta1.AviInfraSettingSpec{
Spec: AviInfraSettingSpec{
SeGroup: akov1beta1.AviInfraSettingSeGroup{
Name: adc.Spec.ServiceEngineGroup,
},
Expand All @@ -343,6 +349,9 @@ func (r *AKODeploymentConfigReconciler) createAviInfraSetting(adc *akoov1alpha1.
},
},
}
u := &unstructured.Unstructured{}
u.Object, _ = runtime.DefaultUnstructuredConverter.ToUnstructured(aviinfraSetting)
return u
}

func (r *AKODeploymentConfigReconciler) reconcileAviInfraSettingDelete(
Expand Down

0 comments on commit aa3f3ac

Please sign in to comment.