Skip to content

Commit

Permalink
Calico APIServer configuration refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamas-Biro1 committed Nov 5, 2024
1 parent 88031b9 commit 657730b
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 473 deletions.
1 change: 1 addition & 0 deletions api/v1/apiserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,6 @@ func (c *APIServerDeployment) GetPriorityClassName() string {
return c.Spec.Template.Spec.PriorityClassName
}
}

return ""
}
3 changes: 0 additions & 3 deletions api/v1/installation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
9 changes: 0 additions & 9 deletions pkg/controller/installation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 0 additions & 33 deletions pkg/controller/installation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 0 additions & 98 deletions pkg/controller/utils/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down
Loading

0 comments on commit 657730b

Please sign in to comment.