From 657730b1e79b18d669ab28d5fefd48168965b6d5 Mon Sep 17 00:00:00 2001 From: Tamas-Biro1 <60390128+Tamas-Biro1@users.noreply.github.com> Date: Thu, 29 Aug 2024 09:40:17 +0200 Subject: [PATCH] Calico APIServer configuration refactor --- api/v1/apiserver_types.go | 1 + api/v1/installation_types.go | 3 - pkg/controller/installation/validation.go | 9 - .../installation/validation_test.go | 33 -- pkg/controller/utils/merge.go | 98 ------ pkg/controller/utils/merge_test.go | 307 ------------------ pkg/render/apiserver.go | 23 +- pkg/render/apiserver_test.go | 9 +- 8 files changed, 10 insertions(+), 473 deletions(-) diff --git a/api/v1/apiserver_types.go b/api/v1/apiserver_types.go index cc9d835b13..b7223c8dd3 100644 --- a/api/v1/apiserver_types.go +++ b/api/v1/apiserver_types.go @@ -313,5 +313,6 @@ func (c *APIServerDeployment) GetPriorityClassName() string { return c.Spec.Template.Spec.PriorityClassName } } + return "" } diff --git a/api/v1/installation_types.go b/api/v1/installation_types.go index b2eb879c1a..41287db102 100644 --- a/api/v1/installation_types.go +++ b/api/v1/installation_types.go @@ -173,9 +173,6 @@ type InstallationSpec struct { // ComponentResources or TyphaAffinity, then these overrides take precedence. TyphaDeployment *TyphaDeployment `json:"typhaDeployment,omitempty"` - // CalicoApiserverDeployment configures the apiserver Deployment. - APIServerDeployment *APIServerDeployment `json:"apiserverDeployment,omitempty"` - // Deprecated. The CalicoWindowsUpgradeDaemonSet is deprecated and will be removed from the API in the future. // CalicoWindowsUpgradeDaemonSet configures the calico-windows-upgrade DaemonSet. CalicoWindowsUpgradeDaemonSet *CalicoWindowsUpgradeDaemonSet `json:"calicoWindowsUpgradeDaemonSet,omitempty"` diff --git a/pkg/controller/installation/validation.go b/pkg/controller/installation/validation.go index a11bbaafdf..a5063f0b43 100644 --- a/pkg/controller/installation/validation.go +++ b/pkg/controller/installation/validation.go @@ -23,7 +23,6 @@ import ( operatorv1 "github.com/tigera/operator/api/v1" "github.com/tigera/operator/pkg/common" "github.com/tigera/operator/pkg/common/validation" - apiserver "github.com/tigera/operator/pkg/common/validation/apiserver" node "github.com/tigera/operator/pkg/common/validation/calico-node" csinodedriver "github.com/tigera/operator/pkg/common/validation/csi-node-driver" kubecontrollers "github.com/tigera/operator/pkg/common/validation/kube-controllers" @@ -375,14 +374,6 @@ func validateCustomResource(instance *operatorv1.Installation) error { } } - // Verify the APIServerDeployment overrides, if specified, is valid. - if deploy := instance.Spec.APIServerDeployment; deploy != nil { - err := validation.ValidateReplicatedPodResourceOverrides(deploy, apiserver.ValidateAPIServerDeploymentContainer, apiserver.ValidateAPIServerDeploymentInitContainer) - if err != nil { - return fmt.Errorf("Installation spec.APIServerDeployment is not valid: %w", err) - } - } - // Verify the CSINodeDriverDaemonSet overrides, if specified, is valid. if ds := instance.Spec.CSINodeDriverDaemonSet; ds != nil { err := validation.ValidateReplicatedPodResourceOverrides(ds, csinodedriver.ValidateCSINodeDriverDaemonSetContainer, validation.NoContainersDefined) diff --git a/pkg/controller/installation/validation_test.go b/pkg/controller/installation/validation_test.go index d519545f29..50255dd63d 100644 --- a/pkg/controller/installation/validation_test.go +++ b/pkg/controller/installation/validation_test.go @@ -959,39 +959,6 @@ var _ = Describe("Installation validation tests", func() { Expect(err).To(HaveOccurred()) }) }) - - Describe("validate APIServerDeployment", func() { - It("should return nil when it is empty", func() { - instance.Spec.APIServerDeployment = &operator.APIServerDeployment{} - err := validateCustomResource(instance) - Expect(err).NotTo(HaveOccurred()) - }) - - It("should return an error if it is invalid", func() { - instance.Spec.APIServerDeployment = &operator.APIServerDeployment{ - Metadata: &operator.Metadata{ - Labels: map[string]string{ - "NoUppercaseOrSpecialCharsLike=Equals": "b", - "WowNoUppercaseOrSpecialCharsLike=Equals": "b", - }, - Annotations: map[string]string{ - "AnnotNoUppercaseOrSpecialCharsLike=Equals": "bar", - }, - }, - } - err := validateCustomResource(instance) - Expect(err).To(HaveOccurred()) - - var invalidMinReadySeconds int32 = -1 - instance.Spec.APIServerDeployment = &operator.APIServerDeployment{ - Spec: &operator.APIServerDeploymentSpec{ - MinReadySeconds: &invalidMinReadySeconds, - }, - } - err = validateCustomResource(instance) - Expect(err).To(HaveOccurred()) - }) - }) Describe("validate Windows configuration", func() { BeforeEach(func() { winDpHNS := operator.WindowsDataplaneHNS diff --git a/pkg/controller/utils/merge.go b/pkg/controller/utils/merge.go index 64eeffb063..ad4bb78253 100644 --- a/pkg/controller/utils/merge.go +++ b/pkg/controller/utils/merge.go @@ -180,13 +180,6 @@ func OverrideInstallationSpec(cfg, override operatorv1.InstallationSpec) operato inst.TyphaDeployment = mergeTyphaDeployment(inst.TyphaDeployment, override.TyphaDeployment) } - switch compareFields(inst.APIServerDeployment, override.APIServerDeployment) { - case BOnlySet: - inst.APIServerDeployment = override.APIServerDeployment.DeepCopy() - case Different: - inst.APIServerDeployment = mergeAPIServerDeployment(inst.APIServerDeployment, override.APIServerDeployment) - } - switch compareFields(inst.CalicoWindowsUpgradeDaemonSet, override.CalicoWindowsUpgradeDaemonSet) { case BOnlySet: inst.CalicoWindowsUpgradeDaemonSet = override.CalicoWindowsUpgradeDaemonSet.DeepCopy() @@ -777,97 +770,6 @@ func mergeTyphaDeployment(cfg, override *operatorv1.TyphaDeployment) *operatorv1 return out } -func mergeAPIServerDeployment(cfg, override *operatorv1.APIServerDeployment) *operatorv1.APIServerDeployment { - out := cfg.DeepCopy() - - switch compareFields(out.Metadata, override.Metadata) { - case BOnlySet: - out.Metadata = override.Metadata.DeepCopy() - case Different: - out.Metadata = mergeMetadata(out.Metadata, override.Metadata) - } - - mergePodSpec := func(cfg, override *operatorv1.APIServerDeploymentPodSpec) *operatorv1.APIServerDeploymentPodSpec { - out := cfg.DeepCopy() - - switch compareFields(out.InitContainers, override.InitContainers) { - case BOnlySet, Different: - out.InitContainers = make([]operatorv1.APIServerDeploymentInitContainer, len(override.Containers)) - copy(out.InitContainers, override.InitContainers) - } - - switch compareFields(out.Containers, override.Containers) { - case BOnlySet, Different: - out.Containers = make([]operatorv1.APIServerDeploymentContainer, len(override.Containers)) - copy(out.Containers, override.Containers) - } - - switch compareFields(out.Affinity, override.Affinity) { - case BOnlySet, Different: - out.Affinity = override.Affinity - } - - switch compareFields(out.NodeSelector, override.NodeSelector) { - case BOnlySet, Different: - out.NodeSelector = override.NodeSelector - } - - switch compareFields(out.TopologySpreadConstraints, override.TopologySpreadConstraints) { - case BOnlySet, Different: - out.TopologySpreadConstraints = override.TopologySpreadConstraints - } - - switch compareFields(out.Tolerations, override.Tolerations) { - case BOnlySet, Different: - out.Tolerations = override.Tolerations - } - return out - } - mergeTemplateSpec := func(cfg, override *operatorv1.APIServerDeploymentPodTemplateSpec) *operatorv1.APIServerDeploymentPodTemplateSpec { - out := cfg.DeepCopy() - - switch compareFields(out.Metadata, override.Metadata) { - case BOnlySet: - out.Metadata = override.Metadata.DeepCopy() - case Different: - out.Metadata = mergeMetadata(out.Metadata, override.Metadata) - } - - switch compareFields(out.Spec, override.Spec) { - case BOnlySet: - out.Spec = override.Spec.DeepCopy() - case Different: - out.Spec = mergePodSpec(out.Spec, override.Spec) - } - - return out - } - mergeSpec := func(cfg, override *operatorv1.APIServerDeploymentSpec) *operatorv1.APIServerDeploymentSpec { - out := cfg.DeepCopy() - - switch compareFields(out.MinReadySeconds, override.MinReadySeconds) { - case BOnlySet, Different: - out.MinReadySeconds = override.MinReadySeconds - } - - switch compareFields(out.Template, override.Template) { - case BOnlySet: - out.Template = override.Template.DeepCopy() - case Different: - out.Template = mergeTemplateSpec(out.Template, override.Template) - } - return out - } - - switch compareFields(out.Spec, override.Spec) { - case BOnlySet: - out.Spec = override.Spec.DeepCopy() - case Different: - out.Spec = mergeSpec(out.Spec, override.Spec) - } - return out -} - func mergeCalicoWindowsUpgradeDaemonSet(cfg, override *operatorv1.CalicoWindowsUpgradeDaemonSet) *operatorv1.CalicoWindowsUpgradeDaemonSet { out := cfg.DeepCopy() diff --git a/pkg/controller/utils/merge_test.go b/pkg/controller/utils/merge_test.go index c5f7798ec8..874d7fc2cf 100644 --- a/pkg/controller/utils/merge_test.go +++ b/pkg/controller/utils/merge_test.go @@ -1508,313 +1508,6 @@ var _ = Describe("Installation merge tests", func() { Context("test TyphaDeployment merge", func() { // TODO }) - - Context("test APIServerDeployment merge", func() { - var m opv1.InstallationSpec - var s opv1.InstallationSpec - - BeforeEach(func() { - m = opv1.InstallationSpec{ - APIServerDeployment: &opv1.APIServerDeployment{ - Spec: &opv1.APIServerDeploymentSpec{ - Template: &opv1.APIServerDeploymentPodTemplateSpec{ - Spec: &opv1.APIServerDeploymentPodSpec{}, - }, - }, - }, - } - s = opv1.InstallationSpec{ - APIServerDeployment: &opv1.APIServerDeployment{ - Spec: &opv1.APIServerDeploymentSpec{ - Template: &opv1.APIServerDeploymentPodTemplateSpec{ - Spec: &opv1.APIServerDeploymentPodSpec{}, - }, - }, - }, - } - }) - - DescribeTable("merge metadata", func(main, second, expect *opv1.Metadata) { - // start with empty installation spec - m = opv1.InstallationSpec{} - s = opv1.InstallationSpec{} - if main != nil { - m.APIServerDeployment = &opv1.APIServerDeployment{Metadata: main} - } - if second != nil { - s.APIServerDeployment = &opv1.APIServerDeployment{Metadata: second} - } - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.APIServerDeployment).To(BeNil()) - } else { - Expect(*inst.APIServerDeployment.Metadata).To(Equal(*expect)) - } - }, metadataTests...) - - DescribeTable("merge pod template metadata", func(main, second, expect *opv1.Metadata) { - m.APIServerDeployment.Spec.Template.Metadata = main - s.APIServerDeployment.Spec.Template.Metadata = second - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.APIServerDeployment.Spec.Template.Metadata).To(BeNil()) - } else { - Expect(*inst.APIServerDeployment.Spec.Template.Metadata).To(Equal(*expect)) - } - }, metadataTests...) - - _resources1 := &v1.ResourceRequirements{ - Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("500m")}, - Limits: v1.ResourceList{v1.ResourceCPU: resource.MustParse("500m")}, - } - _resources2 := &v1.ResourceRequirements{ - Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1000m"), v1.ResourceMemory: resource.MustParse("500Mi")}, - Limits: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1000m"), v1.ResourceMemory: resource.MustParse("1000Mi")}, - } - - _apiServerInit1a := opv1.APIServerDeploymentInitContainer{Name: "init1", Resources: _resources1} - _apiServerInit1b := opv1.APIServerDeploymentInitContainer{Name: "init1", Resources: _resources2} - _apiServerInit2 := opv1.APIServerDeploymentInitContainer{Name: "init2", Resources: _resources2} - - DescribeTable("merge initContainers", func(main, second, expect []opv1.APIServerDeploymentInitContainer) { - m.APIServerDeployment.Spec.Template.Spec.InitContainers = main - s.APIServerDeployment.Spec.Template.Spec.InitContainers = second - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.CalicoNodeDaemonSet.Spec.Template.Spec.InitContainers).To(BeNil()) - } else { - Expect(inst.CalicoNodeDaemonSet.Spec.Template.Spec.InitContainers).To(Equal(expect)) - } - }, - Entry("Both unset", nil, nil, nil), - Entry("Main only set", []opv1.APIServerDeploymentInitContainer{_apiServerInit1a, _apiServerInit2}, nil, []opv1.APIServerDeploymentInitContainer{_apiServerInit1a, _apiServerInit2}), - Entry("Second only set", nil, []opv1.APIServerDeploymentInitContainer{_apiServerInit1a, _apiServerInit2}, []opv1.APIServerDeploymentInitContainer{_apiServerInit1a, _apiServerInit2}), - Entry("Both set equal", []opv1.APIServerDeploymentInitContainer{_apiServerInit1a, _apiServerInit2}, []opv1.APIServerDeploymentInitContainer{_apiServerInit1a, _apiServerInit2}, - []opv1.APIServerDeploymentInitContainer{_apiServerInit1a, _apiServerInit2}), - Entry("Both set not equal", []opv1.APIServerDeploymentInitContainer{_apiServerInit1a, _apiServerInit2}, []opv1.APIServerDeploymentInitContainer{_apiServerInit1b, _apiServerInit2}, - []opv1.APIServerDeploymentInitContainer{_apiServerInit1b, _apiServerInit2}), - ) - - _apiServer1a := opv1.APIServerDeploymentContainer{Name: "apis1"} - _apiServer1b := opv1.APIServerDeploymentContainer{Name: "apis1"} - _apiServer2 := opv1.APIServerDeploymentContainer{Name: "apis2"} - - DescribeTable("merge containers", func(main, second, expect []opv1.APIServerDeploymentContainer) { - m.APIServerDeployment.Spec.Template.Spec.Containers = main - s.APIServerDeployment.Spec.Template.Spec.Containers = second - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.CSINodeDriverDaemonSet.Spec.Template.Spec.Containers).To(BeNil()) - } else { - Expect(inst.CSINodeDriverDaemonSet.Spec.Template.Spec.Containers).To(Equal(expect)) - } - }, - Entry("Both unset", nil, nil, nil), - Entry("Main only set", []opv1.APIServerDeploymentContainer{_apiServer1a, _apiServer1b}, nil, []opv1.APIServerDeploymentContainer{_apiServer1a, _apiServer1b}), - Entry("Second only set", nil, []opv1.APIServerDeploymentContainer{_apiServer1a, _apiServer1b}, []opv1.APIServerDeploymentContainer{_apiServer1a, _apiServer1b}), - Entry("Both set equal", []opv1.APIServerDeploymentContainer{_apiServer1a, _apiServer1b}, []opv1.APIServerDeploymentContainer{_apiServer1a, _apiServer1b}, - []opv1.APIServerDeploymentContainer{_apiServer1a, _apiServer1b}), - Entry("Both set not equal", []opv1.APIServerDeploymentContainer{_apiServer1a, _apiServer2}, []opv1.APIServerDeploymentContainer{_apiServer1b, _apiServer2}, - []opv1.APIServerDeploymentContainer{_apiServer1b, _apiServer2}), - ) - - _aff1 := &v1.Affinity{ - NodeAffinity: &v1.NodeAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{ - NodeSelectorTerms: []v1.NodeSelectorTerm{{ - MatchExpressions: []v1.NodeSelectorRequirement{{ - Key: "custom-affinity-key", - Operator: v1.NodeSelectorOpExists, - }}, - }}, - }, - }, - } - _aff2 := &v1.Affinity{ - NodeAffinity: &v1.NodeAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{ - NodeSelectorTerms: []v1.NodeSelectorTerm{{ - MatchExpressions: []v1.NodeSelectorRequirement{{ - Key: "custom-affinity-key2", - Operator: v1.NodeSelectorOpExists, - }}, - }}, - }, - }, - } - _affEmpty := &v1.Affinity{} - - DescribeTable("merge affinity", func(main, second, expect *v1.Affinity) { - m.APIServerDeployment.Spec.Template.Spec.Affinity = main - s.APIServerDeployment.Spec.Template.Spec.Affinity = second - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.APIServerDeployment.Spec.Template.Spec.Affinity).To(BeNil()) - } else { - Expect(*inst.APIServerDeployment.Spec.Template.Spec.Affinity).To(Equal(*expect)) - } - }, - Entry("Both unset", nil, nil, nil), - Entry("Main only set", _aff1, nil, _aff1), - Entry("Second only set", nil, _aff1, _aff1), - Entry("Both set equal", _aff1, _aff1, _aff1), - Entry("Both set not equal", _aff1, _aff2, _aff2), - Entry("Both set not equal, override empty", _aff1, _affEmpty, _affEmpty), - ) - - DescribeTable("merge nodeSelector", func(main, second, expect map[string]string) { - m.APIServerDeployment.Spec.Template.Spec.NodeSelector = main - s.APIServerDeployment.Spec.Template.Spec.NodeSelector = second - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.APIServerDeployment.Spec.Template.Spec.NodeSelector).To(BeNil()) - } else { - Expect(inst.APIServerDeployment.Spec.Template.Spec.NodeSelector).To(Equal(expect)) - } - }, - Entry("Both unset", nil, nil, nil), - Entry("Main only set", map[string]string{"a1": "1"}, nil, map[string]string{"a1": "1"}), - Entry("Second only set", nil, map[string]string{"a1": "1"}, map[string]string{"a1": "1"}), - Entry("Both set equal", map[string]string{"a1": "1"}, map[string]string{"a1": "1"}, map[string]string{"a1": "1"}), - Entry("Both set not equal", map[string]string{"a1": "1"}, map[string]string{"a1": "2", "b1": "3"}, map[string]string{"a1": "2", "b1": "3"}), - Entry("Both set not equal, override empty", map[string]string{"a1": "1"}, map[string]string{}, map[string]string{}), - ) - - _topology1 := v1.TopologySpreadConstraint{ - MaxSkew: 1, - TopologyKey: "foo", - WhenUnsatisfiable: v1.ScheduleAnyway, - } - _topology2 := v1.TopologySpreadConstraint{ - MaxSkew: 1, - TopologyKey: "bar", - WhenUnsatisfiable: v1.ScheduleAnyway, - } - - DescribeTable("merge topology spread constraints", func(main, second, expect []v1.TopologySpreadConstraint) { - m.APIServerDeployment.Spec.Template.Spec.TopologySpreadConstraints = main - s.APIServerDeployment.Spec.Template.Spec.TopologySpreadConstraints = second - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.APIServerDeployment.Spec.Template.Spec.TopologySpreadConstraints).To(BeNil()) - } else { - Expect(inst.APIServerDeployment.Spec.Template.Spec.TopologySpreadConstraints).To(Equal(expect)) - } - }, - Entry("Both unset", nil, nil, nil), - Entry("Main only set", []v1.TopologySpreadConstraint{_topology1}, nil, []v1.TopologySpreadConstraint{_topology1}), - Entry("Second only set", nil, []v1.TopologySpreadConstraint{_topology1}, []v1.TopologySpreadConstraint{_topology1}), - Entry("Both set equal", []v1.TopologySpreadConstraint{_topology1}, []v1.TopologySpreadConstraint{_topology1}, []v1.TopologySpreadConstraint{_topology1}), - Entry("Both set not equal", []v1.TopologySpreadConstraint{_topology1}, []v1.TopologySpreadConstraint{_topology2}, []v1.TopologySpreadConstraint{_topology2}), - Entry("Both set not equal, override empty", []v1.TopologySpreadConstraint{_topology1}, []v1.TopologySpreadConstraint{}, []v1.TopologySpreadConstraint{}), - ) - - _toleration1 := v1.Toleration{ - Key: "foo", - Operator: v1.TolerationOpEqual, - Value: "bar", - } - _toleration2 := v1.Toleration{ - Key: "bar", - Operator: v1.TolerationOpEqual, - Value: "baz", - } - - DescribeTable("merge tolerations", func(main, second, expect []v1.Toleration) { - m.APIServerDeployment.Spec.Template.Spec.Tolerations = main - s.APIServerDeployment.Spec.Template.Spec.Tolerations = second - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.APIServerDeployment.Spec.Template.Spec.Tolerations).To(BeNil()) - } else { - Expect(inst.APIServerDeployment.Spec.Template.Spec.Tolerations).To(Equal(expect)) - } - }, - Entry("Both unset", nil, nil, nil), - Entry("Main only set", []v1.Toleration{_toleration1}, nil, []v1.Toleration{_toleration1}), - Entry("Second only set", nil, []v1.Toleration{_toleration1}, []v1.Toleration{_toleration1}), - Entry("Both set equal", []v1.Toleration{_toleration1}, []v1.Toleration{_toleration1}, []v1.Toleration{_toleration1}), - Entry("Both set not equal", []v1.Toleration{_toleration1}, []v1.Toleration{_toleration2}, []v1.Toleration{_toleration2}), - Entry("Both set not equal, override empty", []v1.Toleration{_toleration1}, []v1.Toleration{}, []v1.Toleration{}), - ) - - DescribeTable("merge multiple APIServerDeployment fields", func(main, second, expect *opv1.APIServerDeployment) { - // start with empty spec - m = opv1.InstallationSpec{} - s = opv1.InstallationSpec{} - if main != nil { - m.APIServerDeployment = main - } - if second != nil { - s.APIServerDeployment = second - } - inst := OverrideInstallationSpec(m, s) - if expect == nil { - Expect(inst.APIServerDeployment).To(BeNil()) - } else { - Expect(*inst.APIServerDeployment).To(Equal(*expect)) - } - }, - Entry("Both unset", nil, nil, nil), - Entry("Different fields in the two are merged, some overridden", - &opv1.APIServerDeployment{ - Metadata: &opv1.Metadata{ - Labels: map[string]string{"l": "1"}, - }, - Spec: &opv1.APIServerDeploymentSpec{ - MinReadySeconds: intPtr(5), - Template: &opv1.APIServerDeploymentPodTemplateSpec{ - Spec: &opv1.APIServerDeploymentPodSpec{ - Containers: []opv1.APIServerDeploymentContainer{_apiServer1a}, - NodeSelector: map[string]string{"selector": "test"}, - Tolerations: []v1.Toleration{_toleration1}, - }, - }, - }, - }, - &opv1.APIServerDeployment{ - Metadata: &opv1.Metadata{ - Labels: map[string]string{"overridden": "1"}, - Annotations: map[string]string{"a": "1"}, - }, - Spec: &opv1.APIServerDeploymentSpec{ - Template: &opv1.APIServerDeploymentPodTemplateSpec{ - Metadata: &opv1.Metadata{ - Labels: map[string]string{"pod-label": "1"}, - Annotations: map[string]string{"pod-annot": "1"}, - }, - Spec: &opv1.APIServerDeploymentPodSpec{ - Affinity: _aff1, - NodeSelector: map[string]string{"overridden": "selector"}, - Tolerations: []v1.Toleration{}, - }, - }, - }, - }, - &opv1.APIServerDeployment{ - Metadata: &opv1.Metadata{ - Labels: map[string]string{"overridden": "1"}, - Annotations: map[string]string{"a": "1"}, - }, - Spec: &opv1.APIServerDeploymentSpec{ - MinReadySeconds: intPtr(5), - Template: &opv1.APIServerDeploymentPodTemplateSpec{ - Metadata: &opv1.Metadata{ - Labels: map[string]string{"pod-label": "1"}, - Annotations: map[string]string{"pod-annot": "1"}, - }, - Spec: &opv1.APIServerDeploymentPodSpec{ - Containers: []opv1.APIServerDeploymentContainer{_apiServer1a}, - Affinity: _aff1, - NodeSelector: map[string]string{"overridden": "selector"}, - Tolerations: []v1.Toleration{}, - }, - }, - }, - }, - )) - }) - Context("test CalicoWindowsUpgradeDaemonSet merge", func() { // TODO }) diff --git a/pkg/render/apiserver.go b/pkg/render/apiserver.go index 510629b4d2..06247123c1 100644 --- a/pkg/render/apiserver.go +++ b/pkg/render/apiserver.go @@ -946,7 +946,7 @@ func (c *apiServerComponent) apiServerDeployment() *appsv1.Deployment { Spec: appsv1.DeploymentSpec{ Replicas: c.cfg.Installation.ControlPlaneReplicas, Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RecreateDeploymentStrategyType, + Type: appsv1.RollingUpdateDeploymentStrategyType, }, Selector: c.deploymentSelector(), Template: corev1.PodTemplateSpec{ @@ -969,8 +969,7 @@ func (c *apiServerComponent) apiServerDeployment() *appsv1.Deployment { Containers: []corev1.Container{ c.apiServerContainer(), }, - Volumes: c.apiServerVolumes(), - PriorityClassName: c.priorityClassName(), + Volumes: c.apiServerVolumes(), }, }, }, @@ -1044,16 +1043,6 @@ func (c *apiServerComponent) apiServerContainer() corev1.Container { Args: c.startUpArgs(), Env: env, VolumeMounts: volumeMounts, - LivenessProbe: &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Path: "/version", - Port: intstr.FromInt(APIServerPort), - Scheme: corev1.URISchemeHTTPS, - }, - }, - PeriodSeconds: 60, - }, ReadinessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ @@ -1204,14 +1193,6 @@ func (c *apiServerComponent) tolerations() []corev1.Toleration { return append(c.cfg.Installation.ControlPlaneTolerations, rmeta.TolerateControlPlane...) } -// priorityClassName create -func (c *apiServerComponent) priorityClassName() string { - if c.cfg.Installation.APIServerDeployment != nil && c.cfg.Installation.APIServerDeployment.GetPriorityClassName() != "" { - return c.cfg.Installation.APIServerDeployment.GetPriorityClassName() - } - return ClusterPriorityClassName -} - // networkPolicy returns a NP to allow traffic to the API server. This prevents it from // being cut off from the main API server. The enterprise equivalent is currently handled in manifests. // diff --git a/pkg/render/apiserver_test.go b/pkg/render/apiserver_test.go index d89198f90e..31c3613a9b 100644 --- a/pkg/render/apiserver_test.go +++ b/pkg/render/apiserver_test.go @@ -21,6 +21,7 @@ import ( "fmt" "time" + "github.com/google/go-cmp/cmp/internal/function" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" @@ -1910,6 +1911,8 @@ var _ = Describe("API server rendering tests (Calico)", func() { Value: "bar", } + priorityclassname := "priority" + cfg.APIServer.APIServerDeployment = &operatorv1.APIServerDeployment{ Metadata: &operatorv1.Metadata{ Labels: map[string]string{"top-level": "label1"}, @@ -1938,8 +1941,9 @@ var _ = Describe("API server rendering tests (Calico)", func() { NodeSelector: map[string]string{ "custom-node-selector": "value", }, - Affinity: affinity, - Tolerations: []corev1.Toleration{toleration}, + Affinity: affinity, + Tolerations: []corev1.Toleration{toleration}, + PriorityClassName: priorityclassname, }, }, }, @@ -1999,6 +2003,7 @@ var _ = Describe("API server rendering tests (Calico)", func() { Expect(d.Spec.Template.Spec.Tolerations).To(HaveLen(1)) Expect(d.Spec.Template.Spec.Tolerations[0]).To(Equal(toleration)) + Expect(d.Spec.Template.Spec.PriorityClassName).To(Equal(priorityclassname)) }) It("should override a ControlPlaneNodeSelector when specified", func() {