Skip to content

Commit

Permalink
[release-v1.25] Pick of #1810: windows: only render upgrader componen…
Browse files Browse the repository at this point in the history
…ts on AKS (#1818)

* windows: only render upgrader components on AKS

AKS is the only provider that supports the windows upgrader so don't
create the resources on other providers.

* Remove unused param in render tests
  • Loading branch information
lmm authored Mar 7, 2022
1 parent 0e27ddb commit aba5e67
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
54 changes: 36 additions & 18 deletions pkg/render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func allCalicoComponents(
typhaNodeTLS *render.TyphaNodeTLS,
managerInternalTLSSecret *corev1.Secret,
bt map[string]string,
p operatorv1.Provider,
aci *operatorv1.AmazonCloudIntegration,
up bool,
nodeAppArmorProfile string,
Expand All @@ -62,7 +61,6 @@ func allCalicoComponents(
bgpLayout *corev1.ConfigMap,
logCollector *operatorv1.LogCollector,
) ([]render.Component, error) {

namespaces := render.Namespaces(&render.NamespaceConfiguration{Installation: cr, PullSecrets: pullSecrets})

objs := []client.Object{}
Expand Down Expand Up @@ -190,11 +188,11 @@ var _ = Describe("Rendering tests", func() {
// - 2 ConfigMap for Typha comms (1 in operator namespace and 1 in calico namespace)
// - 7 typha resources (Service, SA, Role, Binding, Deployment, PodDisruptionBudget, PodSecurityPolicy)
// - 6 kube-controllers resources (ServiceAccount, ClusterRole, Binding, Deployment, PodSecurityPolicy, Service, Secret)
// - 2 windows-upgrader resources (ServiceAccount, DaemonSet)
// - 1 namespace
c, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, operatorv1.ProviderNone, nil, false, "", dns.DefaultClusterDomain, 9094, 0, nil, nil)
c, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, "", dns.DefaultClusterDomain, 9094, 0, nil, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
Expect(componentCount(c)).To(Equal(6 + 4 + 2 + 7 + 6 + 2 + 1))
Expect(componentCount(c)).To(Equal(6 + 4 + 2 + 7 + 6 + 1))
Expect(getAKSWindowsUpgraderComponentCount(c)).To(Equal(0))
})

It("should render all resources when variant is Tigera Secure", func() {
Expand All @@ -205,9 +203,10 @@ var _ = Describe("Rendering tests", func() {
var nodeMetricsPort int32 = 9081
instance.Variant = operatorv1.TigeraSecureEnterprise
instance.NodeMetricsPort = &nodeMetricsPort
c, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, operatorv1.ProviderNone, nil, false, "", dns.DefaultClusterDomain, 9094, 0, nil, nil)
c, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, "", dns.DefaultClusterDomain, 9094, 0, nil, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
Expect(componentCount(c)).To(Equal((6 + 4 + 2 + 7 + 6 + 2 + 1) + 1 + 1))
Expect(componentCount(c)).To(Equal((6 + 4 + 2 + 7 + 6 + 1) + 1 + 1))
Expect(getAKSWindowsUpgraderComponentCount(c)).To(Equal(0))
})

It("should render all resources when variant is Tigera Secure and Management Cluster", func() {
Expand All @@ -224,7 +223,7 @@ var _ = Describe("Rendering tests", func() {
Name: render.ManagerInternalTLSSecretName, Namespace: common.OperatorNamespace(),
},
}
c, err := allCalicoComponents(k8sServiceEp, instance, &operatorv1.ManagementCluster{}, nil, nil, typhaNodeTLS, internalManagerTLSSecret, nil, operatorv1.ProviderNone, nil, false, "", dns.DefaultClusterDomain, 9094, 0, nil, nil)
c, err := allCalicoComponents(k8sServiceEp, instance, &operatorv1.ManagementCluster{}, nil, nil, typhaNodeTLS, internalManagerTLSSecret, nil, nil, false, "", dns.DefaultClusterDomain, 9094, 0, nil, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)

expectedResources := []struct {
Expand Down Expand Up @@ -273,10 +272,6 @@ var _ = Describe("Rendering tests", func() {
{render.ManagerInternalTLSSecretName, common.CalicoNamespace, "", "v1", "Secret"},
{common.KubeControllersDeploymentName, "", "policy", "v1beta1", "PodSecurityPolicy"},
{"calico-kube-controllers-metrics", common.CalicoNamespace, "", "v1", "Service"},

// windows upgrader objects.
{common.CalicoWindowsUpgradeResourceName, common.CalicoNamespace, "", "v1", "ServiceAccount"},
{common.CalicoWindowsUpgradeResourceName, common.CalicoNamespace, "apps", "v1", "DaemonSet"},
}

var resources []client.Object
Expand All @@ -289,11 +284,19 @@ var _ = Describe("Rendering tests", func() {
for i, expectedRes := range expectedResources {
rtest.ExpectResource(resources[i], expectedRes.name, expectedRes.ns, expectedRes.group, expectedRes.version, expectedRes.kind)
}
Expect(getAKSWindowsUpgraderComponentCount(c)).To(Equal(0))
})

It("should render windows upgrader resources for AKS", func() {
instance.KubernetesProvider = operatorv1.ProviderAKS
c, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, "", dns.DefaultClusterDomain, 9094, 0, nil, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
Expect(getAKSWindowsUpgraderComponentCount(c)).To(Equal(2))
})

It("should render calico with a apparmor profile if annotation is present in installation", func() {
apparmorProf := "foobar"
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, operatorv1.ProviderNone, nil, false, apparmorProf, dns.DefaultClusterDomain, 0, 0, nil, nil)
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, apparmorProf, dns.DefaultClusterDomain, 0, 0, nil, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
var cn *appsv1.DaemonSet
for _, comp := range comps {
Expand All @@ -317,7 +320,7 @@ var _ = Describe("Rendering tests", func() {
}
bgpLayout.Name = "bgp-layout"
bgpLayout.Namespace = common.OperatorNamespace()
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, operatorv1.ProviderNone, nil, false, "", dns.DefaultClusterDomain, 0, 0, bgpLayout, nil)
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, "", dns.DefaultClusterDomain, 0, 0, bgpLayout, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
var cm *corev1.ConfigMap
var ds *appsv1.DaemonSet
Expand All @@ -342,7 +345,7 @@ var _ = Describe("Rendering tests", func() {
testNode := func(processPath operatorv1.CollectProcessPathOption, expectedHostPID bool) {
var logCollector operatorv1.LogCollector
logCollector.Spec.CollectProcessPath = &processPath
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, operatorv1.ProviderNone, nil, false, "", dns.DefaultClusterDomain, 0, 0, nil, &logCollector)
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, "", dns.DefaultClusterDomain, 0, 0, nil, &logCollector)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
var ds *appsv1.DaemonSet
for _, comp := range comps {
Expand Down Expand Up @@ -373,7 +376,7 @@ var _ = Describe("Rendering tests", func() {
})

It("should set node priority class to system-node-critical", func() {
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, operatorv1.ProviderNone, nil, false, "", dns.DefaultClusterDomain, 0, 0, nil, nil)
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, "", dns.DefaultClusterDomain, 0, 0, nil, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
var cn *appsv1.DaemonSet
for _, comp := range comps {
Expand All @@ -389,7 +392,7 @@ var _ = Describe("Rendering tests", func() {
})

It("should set typha priority class to system-cluster-critical", func() {
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, operatorv1.ProviderNone, nil, false, "", dns.DefaultClusterDomain, 0, 0, nil, nil)
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, "", dns.DefaultClusterDomain, 0, 0, nil, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
var cn *appsv1.Deployment
for _, comp := range comps {
Expand All @@ -405,7 +408,7 @@ var _ = Describe("Rendering tests", func() {
})

It("should set kube controllers priority class to system-cluster-critical", func() {
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, operatorv1.ProviderNone, nil, false, "", dns.DefaultClusterDomain, 0, 0, nil, nil)
comps, err := allCalicoComponents(k8sServiceEp, instance, nil, nil, nil, typhaNodeTLS, nil, nil, nil, false, "", dns.DefaultClusterDomain, 0, 0, nil, nil)
Expect(err).To(BeNil(), "Expected Calico to create successfully %s", err)
var cn *appsv1.Deployment
for _, comp := range comps {
Expand Down Expand Up @@ -433,3 +436,18 @@ func componentCount(components []render.Component) int {
}
return count
}

func getAKSWindowsUpgraderComponentCount(components []render.Component) int {
var resources []client.Object
for _, component := range components {
var toCreate, _ = component.Objects()
resources = append(resources, toCreate...)
}
count := 0
for _, r := range resources {
if r.GetName() == common.CalicoWindowsUpgradeResourceName {
count += 1
}
}
return count
}
3 changes: 3 additions & 0 deletions pkg/render/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (c *windowsComponent) Objects() ([]client.Object, []client.Object) {
c.windowsUpgradeDaemonset(),
}

if c.cr.KubernetesProvider != operatorv1.ProviderAKS {
return nil, objs
}
return objs, nil
}

Expand Down

0 comments on commit aba5e67

Please sign in to comment.