From 3bc9a62be38ea4aea59ec10e6f80356172c994a5 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 5 Sep 2022 17:41:57 +0800 Subject: [PATCH 1/6] fix: set default values for NamespacedIngress Signed-off-by: Lin Yang --- .../namespacedingress/namespacedingress_webhook.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/webhooks/namespacedingress/namespacedingress_webhook.go b/pkg/webhooks/namespacedingress/namespacedingress_webhook.go index 7eb597be..9a00c2b4 100644 --- a/pkg/webhooks/namespacedingress/namespacedingress_webhook.go +++ b/pkg/webhooks/namespacedingress/namespacedingress_webhook.go @@ -35,6 +35,7 @@ import ( admissionregv1 "k8s.io/api/admissionregistration/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" + "k8s.io/utils/pointer" ) const ( @@ -116,6 +117,18 @@ func (w *NamespacedIngressDefaulter) SetDefaults(obj interface{}) { c.Spec.ServiceAccountName = "fsm-namespaced-ingress" } + if c.Spec.LogLevel == 0 { + c.Spec.LogLevel = 2 + } + + if c.Spec.Replicas == nil { + c.Spec.Replicas = pointer.Int32(1) + } + + if c.Spec.TLS.SSLPassthrough.UpstreamPort == 0 { + c.Spec.TLS.SSLPassthrough.UpstreamPort = 443 + } + klog.V(4).Infof("After setting default values, spec=%#v", c.Spec) } From 9d5af6abb2d2c0770e952c8cbc772a317b2cd59a Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 5 Sep 2022 18:16:15 +0800 Subject: [PATCH 2/6] fix: set default values for Cluster Signed-off-by: Lin Yang --- pkg/webhooks/cluster/cluster_webhook.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/webhooks/cluster/cluster_webhook.go b/pkg/webhooks/cluster/cluster_webhook.go index 28943969..4ad41541 100644 --- a/pkg/webhooks/cluster/cluster_webhook.go +++ b/pkg/webhooks/cluster/cluster_webhook.go @@ -36,6 +36,7 @@ import ( admissionregv1 "k8s.io/api/admissionregistration/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" + "k8s.io/utils/pointer" ) const ( @@ -120,15 +121,14 @@ func (w *ClusterDefaulter) SetDefaults(obj interface{}) { } if c.Spec.Replicas == nil { - c.Spec.Replicas = defaultReplicas() + c.Spec.Replicas = pointer.Int32(1) } - klog.V(4).Infof("After setting default values, spec=%#v", c.Spec) -} + if c.Spec.LogLevel == 0 { + c.Spec.LogLevel = 2 + } -func defaultReplicas() *int32 { - var r int32 = 1 - return &r + klog.V(4).Infof("After setting default values, spec=%#v", c.Spec) } type ClusterValidator struct { @@ -169,6 +169,11 @@ func (w *ClusterValidator) ValidateCreate(obj interface{}) error { } } + if !cluster.Spec.IsInCluster && + (cluster.Spec.Kubeconfig == "" || cluster.Spec.Gateway == "" || cluster.Spec.ControlPlaneRepoRootUrl == "") { + return errors.New("spec.Kubeconfig, spec.Gateway & spec.ControlPlaneRepoRootUrl are required if spec.IsInCluster is false") + } + return doValidation(obj) } From 21630b23c75351baa718edb8f24be90847b80078 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 5 Sep 2022 19:26:14 +0800 Subject: [PATCH 3/6] fix: set default values for NamespacedIngress Signed-off-by: Lin Yang --- .../v1alpha1/namespacedingress_types.go | 4 ++++ .../crds/flomesh.io_namespacedingresses.yaml | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/apis/namespacedingress/v1alpha1/namespacedingress_types.go b/apis/namespacedingress/v1alpha1/namespacedingress_types.go index 6db2d7cd..12b65e2f 100644 --- a/apis/namespacedingress/v1alpha1/namespacedingress_types.go +++ b/apis/namespacedingress/v1alpha1/namespacedingress_types.go @@ -43,10 +43,14 @@ type NamespacedIngressSpec struct { // +optional PodAnnotations map[string]string `json:"podAnnotations,omitempty"` + // +kubebuilder:default={enabled: true, port: {name: http, protocol: TCP, port: 80, targetPort: 8000}} + // The http configuration of this ingress controller. // +optional HTTP HTTP `json:"http,omitempty"` + // +kubebuilder:default={enabled: false, port: {name: https, protocol: TCP, port: 443, targetPort: 8443}, sslPassthrough: {enabled: false, upstreamPort: 443}} + // TLS is the configuration of TLS of this ingress controller // +optional TLS TLS `json:"tls,omitempty"` diff --git a/charts/fsm/crds/flomesh.io_namespacedingresses.yaml b/charts/fsm/crds/flomesh.io_namespacedingresses.yaml index 74b2953b..a9e202b2 100644 --- a/charts/fsm/crds/flomesh.io_namespacedingresses.yaml +++ b/charts/fsm/crds/flomesh.io_namespacedingresses.yaml @@ -974,6 +974,13 @@ spec: type: object type: array http: + default: + enabled: true + port: + name: http + port: 80 + protocol: TCP + targetPort: 8000 description: The http configuration of this ingress controller. properties: enabled: @@ -1110,6 +1117,16 @@ spec: an Ingress the most used types are NodePort, and LoadBalancer type: string tls: + default: + enabled: false + port: + name: https + port: 443 + protocol: TCP + targetPort: 8443 + sslPassthrough: + enabled: false + upstreamPort: 443 description: TLS is the configuration of TLS of this ingress controller properties: enabled: From 18d8f404e7fd73a3380c4675f3ea0a013c688cb9 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 5 Sep 2022 20:15:00 +0800 Subject: [PATCH 4/6] fix: use StrategicMergePatch Signed-off-by: Lin Yang --- pkg/helm/helm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index d5b0001a..deda563a 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -172,7 +172,7 @@ func createOrUpdateUnstructured(ctx context.Context, c client.Client, obj *unstr result := controllerutil.OperationResultNone if !reflect.DeepEqual(obj, modifiedObj) { klog.V(5).Infof("Patching Object %s ...", key) - patchData, err := client.Apply.Data(modifiedObj) + patchData, err := client.Merge.Data(modifiedObj) if err != nil { klog.Errorf("Create ApplyPatch err: %s", err) return controllerutil.OperationResultNone, err @@ -182,7 +182,7 @@ func createOrUpdateUnstructured(ctx context.Context, c client.Client, obj *unstr if err := c.Patch( ctx, obj, - client.RawPatch(types.ApplyPatchType, patchData), + client.RawPatch(types.StrategicMergePatchType, patchData), &client.PatchOptions{FieldManager: "fsm", Force: pointer.Bool(true)}, ); err != nil { klog.Errorf("Patch Object %s err: %s", key, err) From 3fc05e9a895d1ec68161697db6f2b7d3ea0af311 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 5 Sep 2022 20:58:55 +0800 Subject: [PATCH 5/6] fix: remove force from PatchOptions Signed-off-by: Lin Yang --- pkg/helm/helm.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index deda563a..a5da8dd7 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -44,7 +44,6 @@ import ( utilyaml "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/klog/v2" - "k8s.io/utils/pointer" "reflect" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -183,7 +182,7 @@ func createOrUpdateUnstructured(ctx context.Context, c client.Client, obj *unstr ctx, obj, client.RawPatch(types.StrategicMergePatchType, patchData), - &client.PatchOptions{FieldManager: "fsm", Force: pointer.Bool(true)}, + &client.PatchOptions{FieldManager: "fsm"}, ); err != nil { klog.Errorf("Patch Object %s err: %s", key, err) return result, err From 76cc1f687fe8ff2f682b5572fea8e2a00b1fa730 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 5 Sep 2022 22:57:28 +0800 Subject: [PATCH 6/6] fix: MergePatchType Signed-off-by: Lin Yang --- pkg/helm/helm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index a5da8dd7..82eb2231 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -181,7 +181,7 @@ func createOrUpdateUnstructured(ctx context.Context, c client.Client, obj *unstr if err := c.Patch( ctx, obj, - client.RawPatch(types.StrategicMergePatchType, patchData), + client.RawPatch(types.MergePatchType, patchData), &client.PatchOptions{FieldManager: "fsm"}, ); err != nil { klog.Errorf("Patch Object %s err: %s", key, err)