Skip to content

Commit

Permalink
Calico apiserver improvements (#3481)
Browse files Browse the repository at this point in the history
Use RollingUpdate strategy for APIserver except when hostNetworked use Recreate. Add priorityClassName configuration field to the APIServer deployment configuration in the APIServer CRD for setting the priority class.

* Calico APIServer configuration
* Calico APIServer configuration refactor
  • Loading branch information
Tamas-Biro1 authored Jan 8, 2025
1 parent 6cc614c commit d9ee77d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
6 changes: 5 additions & 1 deletion api/v1/apiserver_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2020-2025 Tigera, Inc. All rights reserved.
/*
Expand Down Expand Up @@ -150,6 +150,10 @@ type APIServerDeploymentPodSpec struct {
// WARNING: Please note that this field will override the default API server Deployment tolerations.
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`

// PriorityClassName allows to specify a PriorityClass resource to be used.
// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
}

// APIServerDeploymentPodTemplateSpec is the API server Deployment's PodTemplateSpec
Expand Down
4 changes: 4 additions & 0 deletions pkg/crds/operator/operator.tigera.io_apiservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,10 @@ spec:
If omitted, the API server Deployment will use its default value for nodeSelector.
WARNING: Please note that this field will modify the default API server Deployment nodeSelector.
type: object
priorityClassName:
description: PriorityClassName allows to specify a
PriorityClass resource to be used.
type: string
tolerations:
description: |-
Tolerations is the API server pod's tolerations.
Expand Down
6 changes: 4 additions & 2 deletions pkg/render/apiserver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2019-2025 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1013,9 +1013,11 @@ func (c *apiServerComponent) apiServerDeployment() *appsv1.Deployment {
name, _ := c.resourceNameBasedOnVariant("tigera-apiserver", "calico-apiserver")
hostNetwork := c.hostNetwork()
dnsPolicy := corev1.DNSClusterFirst
deploymentStrategyType := appsv1.RollingUpdateDeploymentStrategyType
if hostNetwork {
// Adjust DNS policy so we can access in-cluster services.
dnsPolicy = corev1.DNSClusterFirstWithHostNet
deploymentStrategyType = appsv1.RecreateDeploymentStrategyType
}

var initContainers []corev1.Container
Expand Down Expand Up @@ -1050,7 +1052,7 @@ func (c *apiServerComponent) apiServerDeployment() *appsv1.Deployment {
Spec: appsv1.DeploymentSpec{
Replicas: c.cfg.Installation.ControlPlaneReplicas,
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
Type: deploymentStrategyType,
},
Selector: c.deploymentSelector(),
Template: corev1.PodTemplateSpec{
Expand Down
32 changes: 27 additions & 5 deletions pkg/render/apiserver_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2024 Tigera, Inc. All rights reserved.
// Copyright (c) 2019-2025 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -194,7 +194,7 @@ var _ = Describe("API server rendering tests (Calico Enterprise)", func() {
Expect(d.Labels).To(HaveKeyWithValue("apiserver", "true"))

Expect(*d.Spec.Replicas).To(BeEquivalentTo(2))
Expect(d.Spec.Strategy.Type).To(Equal(appsv1.RecreateDeploymentStrategyType))
Expect(d.Spec.Strategy.Type).To(Equal(appsv1.RollingUpdateDeploymentStrategyType))
Expect(len(d.Spec.Selector.MatchLabels)).To(Equal(1))
Expect(d.Spec.Selector.MatchLabels).To(HaveKeyWithValue("apiserver", "true"))

Expand Down Expand Up @@ -646,6 +646,15 @@ var _ = Describe("API server rendering tests (Calico Enterprise)", func() {
rtest.ExpectK8sServiceEpEnvVars(deployment.Spec.Template.Spec, "k8shost", "1234")
})

It("should set RecreateDeploymentStrategyType if host networked", func() {
cfg.ForceHostNetwork = true
component, err := render.APIServer(cfg)
Expect(err).To(BeNil(), "Expected APIServer to create successfully %s", err)
resources, _ := component.Objects()
d := rtest.GetResource(resources, "tigera-apiserver", "tigera-system", "apps", "v1", "Deployment").(*appsv1.Deployment)
Expect(d.Spec.Strategy.Type).To(Equal(appsv1.RecreateDeploymentStrategyType))
})

It("should add egress policy with Enterprise variant and K8SServiceEndpoint defined", func() {
cfg.K8SServiceEndpoint.Host = "k8shost"
cfg.K8SServiceEndpoint.Port = "1234"
Expand Down Expand Up @@ -1656,7 +1665,7 @@ var _ = Describe("API server rendering tests (Calico)", func() {
Expect(d.Labels).To(HaveKeyWithValue("apiserver", "true"))

Expect(*d.Spec.Replicas).To(BeEquivalentTo(2))
Expect(d.Spec.Strategy.Type).To(Equal(appsv1.RecreateDeploymentStrategyType))
Expect(d.Spec.Strategy.Type).To(Equal(appsv1.RollingUpdateDeploymentStrategyType))
Expect(len(d.Spec.Selector.MatchLabels)).To(Equal(1))
Expect(d.Spec.Selector.MatchLabels).To(HaveKeyWithValue("apiserver", "true"))

Expand Down Expand Up @@ -1826,6 +1835,15 @@ var _ = Describe("API server rendering tests (Calico)", func() {
rtest.ExpectK8sServiceEpEnvVars(deployment.Spec.Template.Spec, "k8shost", "1234")
})

It("should set RecreateDeploymentStrategyType if host networked", func() {
cfg.ForceHostNetwork = true
component, err := render.APIServer(cfg)
Expect(err).To(BeNil(), "Expected APIServer to create successfully %s", err)
resources, _ := component.Objects()
d := rtest.GetResource(resources, "calico-apiserver", "calico-apiserver", "apps", "v1", "Deployment").(*appsv1.Deployment)
Expect(d.Spec.Strategy.Type).To(Equal(appsv1.RecreateDeploymentStrategyType))
})

It("should not set KUBERNETES_SERVICE_... variables if Docker EE using proxy.local", func() {
cfg.K8SServiceEndpoint.Host = "proxy.local"
cfg.K8SServiceEndpoint.Port = "1234"
Expand Down Expand Up @@ -1957,6 +1975,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"},
Expand Down Expand Up @@ -1985,8 +2005,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,
},
},
},
Expand Down Expand Up @@ -2046,6 +2067,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() {
Expand Down

0 comments on commit d9ee77d

Please sign in to comment.