Skip to content

Commit

Permalink
Remove kube-proxy daemonset rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
coutinhop committed Jul 11, 2023
1 parent 2fb212f commit 3aed045
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 117 deletions.
10 changes: 4 additions & 6 deletions pkg/common/kubernetes_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import (
// VersionInfo contains information about the version of Kubernetes API the cluster is using
// Major and Minor fields map to the v<Major>.<Minor>+ part of the version string
type VersionInfo struct {
Major int
Minor int
GitVersion string
Major int
Minor int
}

func GetKubernetesVersion(clientset kubernetes.Interface) (*VersionInfo, error) {
Expand All @@ -48,9 +47,8 @@ func GetKubernetesVersion(clientset kubernetes.Interface) (*VersionInfo, error)
}

return &VersionInfo{
Major: major,
Minor: minor,
GitVersion: v.GitVersion,
Major: major,
Minor: minor,
}, nil
}

Expand Down
8 changes: 0 additions & 8 deletions pkg/controller/installation/core_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,13 +1349,6 @@ func (r *ReconcileInstallation) Reconcile(ctx context.Context, request reconcile
r.status.SetDegraded(operator.ResourceReadError, fmt.Sprintf("Services endpoint configmap '%s' does not have all required information for Windows configuration", render.K8sSvcEndpointConfigMapName), err, reqLogger)
}

kubernetesVersionInfo, err := common.GetKubernetesVersion(r.clientset)
if err != nil {
r.status.SetDegraded(operator.InternalServerError, "Unable to determine Kubernetes version, defaulting to v1.18.0", err, reqLogger)
kubernetesVersionInfo = &common.VersionInfo{Major: 1, Minor: 18, GitVersion: "v1.18.0-qwerty"}
}
kubernetesVersion := strings.Split(kubernetesVersionInfo.GitVersion, "-")[0]

windowsCfg := render.WindowsConfiguration{
K8sServiceEp: k8sapi.Endpoint,
Installation: &instance.Spec,
Expand All @@ -1366,7 +1359,6 @@ func (r *ReconcileInstallation) Reconcile(ctx context.Context, request reconcile
NodeReporterMetricsPort: nodeReporterMetricsPort,
VXLANVNI: *felixConfiguration.Spec.VXLANVNI,
Terminating: nodeTerminating,
KubernetesVersion: kubernetesVersion,
}
components = append(components, render.Windows(&windowsCfg))
}
Expand Down
17 changes: 0 additions & 17 deletions pkg/controller/installation/core_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ var _ = Describe("Testing core-controller installation", func() {
enterpriseCRDsExist: true,
migrationChecked: true,
tierWatchReady: ready,
clientset: cs, // Needed for GetKubernetesVersion()
}

r.typhaAutoscaler.start(ctx)
Expand Down Expand Up @@ -567,22 +566,6 @@ var _ = Describe("Testing core-controller installation", func() {
fmt.Sprintf("some.registry.org/%s:%s",
components.ComponentTigeraCNIWindows.Image,
components.ComponentTigeraCNIWindows.Version)))
dsKubeProxyWin := appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{Kind: "DaemonSet", APIVersion: "apps/v1"},
ObjectMeta: metav1.ObjectMeta{
Name: common.WindowsKubeProxyDaemonSetName,
Namespace: "kube-system",
},
}
Expect(test.GetResource(c, &dsKubeProxyWin)).To(BeNil())
Expect(dsKubeProxyWin.Spec.Template.Spec.Containers).To(HaveLen(1))
kubeProxyWin := test.GetContainer(dsKubeProxyWin.Spec.Template.Spec.Containers, "kube-proxy")
Expect(kubeProxyWin).ToNot(BeNil())

// When getting kubernetes version fails, it defaults to v1.18.0
kubernetesVersion := "v1.18.0"
Expect(kubeProxyWin.Image).To(Equal(
fmt.Sprintf("sigwindowstools/kube-proxy:%s-calico-hostprocess", kubernetesVersion)))
}
})
It("should use images from imageset", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/installation/typha_autoscaler_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2022 Tigera, Inc. All rights reserved.
// Copyright (c) 2020-2023 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
8 changes: 3 additions & 5 deletions pkg/render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func allCalicoComponents(
AmazonCloudIntegration: aci,
NodeReporterMetricsPort: nodeReporterMetricsPort,
VXLANVNI: 4096,
KubernetesVersion: "v1.18.0",
}

nodeCertComponent := rcertificatemanagement.CertificateManagement(&rcertificatemanagement.Config{
Expand Down Expand Up @@ -211,11 +210,11 @@ var _ = Describe("Rendering tests", func() {
// - 7 typha resources (Service, SA, Role, Binding, Deployment, PodDisruptionBudget, PodSecurityPolicy)
// - 6 kube-controllers resources (ServiceAccount, ClusterRole, Binding, Deployment, PodSecurityPolicy, Service, Secret)
// - 1 namespace
// - 6 Windows node resources (ServiceAccount, ClusterRole, Binding, ConfigMap, DaemonSet, kube-proxy DaemonSet)
// - 5 Windows node resources (ServiceAccount, ClusterRole, Binding, ConfigMap, DaemonSet)
// - 3 Windows calico-cni-plugin resources (ServiceAccount, ClusterRole, ClusterRoleBinding)
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 + 3 + 4 + 1 + 7 + 6 + 1 + 6 + 3))
Expect(componentCount(c)).To(Equal(6 + 3 + 4 + 1 + 7 + 6 + 1 + 5 + 3))
})

It("should render all resources when variant is Tigera Secure", func() {
Expand All @@ -229,7 +228,7 @@ var _ = Describe("Rendering tests", func() {
instance.NodeMetricsPort = &nodeMetricsPort
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 + 3 + 4 + 1 + 7 + 6 + 1 + 6 + 3) + 1 + 1 + 1))
Expect(componentCount(c)).To(Equal((6 + 3 + 4 + 1 + 7 + 6 + 1 + 5 + 3) + 1 + 1 + 1))
})

It("should render all resources when variant is Tigera Secure and Management Cluster", func() {
Expand Down Expand Up @@ -293,7 +292,6 @@ var _ = Describe("Rendering tests", func() {
{render.WindowsNodeMetricsService, common.CalicoNamespace, "", "v1", "Service"},
{"cni-config-windows", common.CalicoNamespace, "", "v1", "ConfigMap"},
{common.WindowsDaemonSetName, common.CalicoNamespace, "apps", "v1", "DaemonSet"},
{common.WindowsKubeProxyDaemonSetName, "kube-system", "apps", "v1", "DaemonSet"},

// Certificate Management objects
{"tigera-ca-bundle", common.CalicoNamespace, "", "v1", "ConfigMap"},
Expand Down
83 changes: 3 additions & 80 deletions pkg/render/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ type WindowsConfiguration struct {
AmazonCloudIntegration *operatorv1.AmazonCloudIntegration
VXLANVNI int
Terminating bool
KubernetesVersion string
}

type windowsComponent struct {
cfg *WindowsConfiguration
cniImage string
nodeImage string
kubeProxyImage string
cfg *WindowsConfiguration
cniImage string
nodeImage string
}

func (c *windowsComponent) ResolveImages(is *operatorv1.ImageSet) error {
Expand All @@ -88,8 +86,6 @@ func (c *windowsComponent) ResolveImages(is *operatorv1.ImageSet) error {
c.nodeImage = appendIfErr(components.GetReference(components.ComponentCalicoNodeWindows, reg, path, prefix, is))
}

c.kubeProxyImage = fmt.Sprintf("sigwindowstools/kube-proxy:%s-calico-hostprocess", c.cfg.KubernetesVersion)

if len(errMsgs) != 0 {
return fmt.Errorf(strings.Join(errMsgs, ","))
}
Expand Down Expand Up @@ -136,8 +132,6 @@ func (c *windowsComponent) Objects() ([]client.Object, []client.Object) {

objs = append(objs, c.windowsDaemonset(cniConfig))

objs = append(objs, c.kubeProxyWindowsDaemonset())

if c.cfg.Terminating {
return objsToKeep, append(objs, objsToDelete...)
}
Expand Down Expand Up @@ -1235,74 +1229,3 @@ func (c *windowsComponent) windowsDaemonset(cniCfgMap *corev1.ConfigMap) *appsv1
}
return &ds
}

// kubeProxyWindowsDaemonset creates the windows kube-proxy daemonset.
// It uses the sigwindowstools/kube-proxy image and is based on
// https://github.com/kubernetes-sigs/sig-windows-tools/blob/master/hostprocess/calico/kube-proxy/kube-proxy.yml
func (c *windowsComponent) kubeProxyWindowsDaemonset() *appsv1.DaemonSet {
ds := appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{Kind: "DaemonSet", APIVersion: "apps/v1"},
ObjectMeta: metav1.ObjectMeta{
Name: common.WindowsKubeProxyDaemonSetName,
Namespace: "kube-system",
Labels: map[string]string{"k8s-app": "kube-proxy"},
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"k8s-app": common.WindowsKubeProxyDaemonSetName,
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"k8s-app": common.WindowsKubeProxyDaemonSetName},
},
Spec: corev1.PodSpec{
NodeSelector: map[string]string{"kubernetes.io/os": "windows"},
Tolerations: rmeta.TolerateAll,
ServiceAccountName: "kube-proxy",
HostNetwork: true,
Containers: []corev1.Container{
c.kubeProxyContainer(),
},
Volumes: []corev1.Volume{
{
Name: "kube-proxy",
VolumeSource: corev1.VolumeSource{ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{Name: "kube-proxy"}}}}},
},
},
UpdateStrategy: c.cfg.Installation.NodeUpdateStrategy,
},
}

return &ds
}

// kubeProxyContainer creates the windows kube-proxy container.
func (c *windowsComponent) kubeProxyContainer() corev1.Container {
return corev1.Container{
Name: "kube-proxy",
Image: c.kubeProxyImage,
Args: []string{"$env:CONTAINER_SANDBOX_MOUNT_POINT/kube-proxy/start.ps1"},
WorkingDir: "$env:CONTAINER_SANDBOX_MOUNT_POINT/kube-proxy/",
SecurityContext: securitycontext.NewWindowsHostProcessContext(),
Env: []corev1.EnvVar{
{
Name: "NODE_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{FieldPath: "spec.nodeName"},
},
},
{
Name: "POD_IP",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{FieldPath: "status.podIP"},
},
},
},
VolumeMounts: []corev1.VolumeMount{
{MountPath: "/var/lib/kube-proxy", Name: "kube-proxy"},
},
}
}

0 comments on commit 3aed045

Please sign in to comment.