Skip to content

Commit

Permalink
revert helm removal
Browse files Browse the repository at this point in the history
  • Loading branch information
maci3jka committed Oct 2, 2024
1 parent 70f0348 commit b33c2fe
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/k8s/pkg/k8sd/features/cilium/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestGatewayEnabled(t *testing.T) {
g.Expect(status.Enabled).To(BeFalse())
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(status.Message).To(Equal(fmt.Sprintf(cilium.GatewayDeployFailedMsgTmpl, err)))
g.Expect(helmM.ApplyCalledWith).To(HaveLen(1))
})

t.Run("AlreadyDeployed", func(t *testing.T) {
Expand All @@ -69,6 +70,11 @@ func TestGatewayEnabled(t *testing.T) {
g.Expect(status.Enabled).To(BeTrue())
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(status.Message).To(Equal(cilium.EnabledMsg))

helmCiliumArgs := helmM.ApplyCalledWith[2]
g.Expect(helmCiliumArgs.Chart).To(Equal(cilium.ChartCilium))
g.Expect(helmCiliumArgs.State).To(Equal(helm.StateUpgradeOnly))
g.Expect(helmCiliumArgs.Values["gatewayAPI"].(map[string]any)["enabled"]).To(Equal(true))
})

t.Run("RolloutFail", func(t *testing.T) {
Expand Down Expand Up @@ -167,6 +173,7 @@ func TestGatewayDisabled(t *testing.T) {
g.Expect(status.Enabled).To(BeFalse())
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(status.Message).To(Equal(fmt.Sprintf(cilium.GatewayDeleteFailedMsgTmpl, err)))
g.Expect(helmM.ApplyCalledWith).To(HaveLen(1))
})

t.Run("AlreadyDeleted", func(t *testing.T) {
Expand Down
32 changes: 32 additions & 0 deletions src/k8s/pkg/k8sd/features/cilium/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func TestIngress(t *testing.T) {
g.Expect(status.Enabled).To(Equal(tc.statusEnabled))
g.Expect(status.Message).To(Equal(tc.statusMsg))
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(helmM.ApplyCalledWith).To(HaveLen(1))

callArgs := helmM.ApplyCalledWith[0]
g.Expect(callArgs.Chart).To(Equal(cilium.ChartCilium))
validateIngressValues(g, callArgs.Values, ingress)
})
}
}
Expand Down Expand Up @@ -133,6 +138,11 @@ func TestIngressRollout(t *testing.T) {
g.Expect(status.Enabled).To(BeFalse())
g.Expect(status.Message).To(Equal(fmt.Sprintf(cilium.IngressDeployFailedMsgTmpl, err)))
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(helmM.ApplyCalledWith).To(HaveLen(1))

callArgs := helmM.ApplyCalledWith[0]
g.Expect(callArgs.Chart).To(Equal(cilium.ChartCilium))
validateIngressValues(g, callArgs.Values, ingress)
})

t.Run("Success", func(t *testing.T) {
Expand Down Expand Up @@ -174,5 +184,27 @@ func TestIngressRollout(t *testing.T) {
g.Expect(status.Enabled).To(BeTrue())
g.Expect(status.Message).To(Equal(cilium.EnabledMsg))
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(helmM.ApplyCalledWith).To(HaveLen(1))

callArgs := helmM.ApplyCalledWith[0]
g.Expect(callArgs.Chart).To(Equal(cilium.ChartCilium))
validateIngressValues(g, callArgs.Values, ingress)
})
}

func validateIngressValues(g Gomega, values map[string]any, ingress types.Ingress) {
ingressController, ok := values["ingressController"].(map[string]any)
g.Expect(ok).To(BeTrue())
if ingress.GetEnabled() {
g.Expect(ingressController["enabled"]).To(Equal(true))
g.Expect(ingressController["loadbalancerMode"]).To(Equal("shared"))
g.Expect(ingressController["defaultSecretNamespace"]).To(Equal("kube-system"))
g.Expect(ingressController["defaultTLSSecret"]).To(Equal(ingress.GetDefaultTLSSecret()))
g.Expect(ingressController["enableProxyProtocol"]).To(Equal(ingress.GetEnableProxyProtocol()))
} else {
g.Expect(ingressController["enabled"]).To(Equal(false))
g.Expect(ingressController["defaultSecretNamespace"]).To(Equal(""))
g.Expect(ingressController["defaultSecretName"]).To(Equal(""))
g.Expect(ingressController["enableProxyProtocol"]).To(Equal(false))
}
}
78 changes: 78 additions & 0 deletions src/k8s/pkg/k8sd/features/cilium/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"testing"

"github.com/canonical/k8s/pkg/client/helm"
helmmock "github.com/canonical/k8s/pkg/client/helm/mock"
"github.com/canonical/k8s/pkg/client/kubernetes"
"github.com/canonical/k8s/pkg/k8sd/features/cilium"
Expand Down Expand Up @@ -44,6 +45,12 @@ func TestLoadBalancerDisabled(t *testing.T) {
g.Expect(status.Enabled).To(BeFalse())
g.Expect(status.Message).To(Equal(fmt.Sprintf(cilium.LbDeleteFailedMsgTmpl, err)))
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(helmM.ApplyCalledWith).To(HaveLen(1))

callArgs := helmM.ApplyCalledWith[0]
g.Expect(callArgs.Chart).To(Equal(cilium.ChartCiliumLoadBalancer))
g.Expect(callArgs.State).To(Equal(helm.StateDeleted))
g.Expect(callArgs.Values).To(BeNil())
})

t.Run("Success", func(t *testing.T) {
Expand All @@ -68,6 +75,17 @@ func TestLoadBalancerDisabled(t *testing.T) {
g.Expect(status.Enabled).To(BeFalse())
g.Expect(status.Message).To(Equal(cilium.DisabledMsg))
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(helmM.ApplyCalledWith).To(HaveLen(2))

firstCallArgs := helmM.ApplyCalledWith[0]
g.Expect(firstCallArgs.Chart).To(Equal(cilium.ChartCiliumLoadBalancer))
g.Expect(firstCallArgs.State).To(Equal(helm.StateDeleted))
g.Expect(firstCallArgs.Values).To(BeNil())

// checking helm apply for network since it's enabled
secondCallArgs := helmM.ApplyCalledWith[1]
g.Expect(secondCallArgs.Chart).To(Equal(cilium.ChartCilium))
g.Expect(secondCallArgs.State).To(Equal(helm.StateUpgradeOnlyOrDeleted(networkCfg.GetEnabled())))
})
}

Expand Down Expand Up @@ -100,6 +118,17 @@ func TestLoadBalancerEnabled(t *testing.T) {
g.Expect(status.Enabled).To(BeFalse())
g.Expect(status.Message).To(Equal(fmt.Sprintf(cilium.LbDeployFailedMsgTmpl, err)))
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(helmM.ApplyCalledWith).To(HaveLen(1))

callArgs := helmM.ApplyCalledWith[0]
g.Expect(callArgs.Chart).To(Equal(cilium.ChartCilium))
g.Expect(callArgs.State).To(Equal(helm.StateUpgradeOnlyOrDeleted(networkCfg.GetEnabled())))
l2announcements, ok := callArgs.Values["l2announcements"].(map[string]any)
g.Expect(ok).To(BeTrue())
g.Expect(l2announcements["enabled"]).To(Equal(lbCfg.GetL2Mode()))
bgpControlPlane, ok := callArgs.Values["bgpControlPlane"].(map[string]any)
g.Expect(ok).To(BeTrue())
g.Expect(bgpControlPlane["enabled"]).To(Equal(lbCfg.GetBGPMode()))
})

for _, tc := range []struct {
Expand Down Expand Up @@ -191,6 +220,23 @@ func TestLoadBalancerEnabled(t *testing.T) {
g.Expect(status.Version).To(Equal(cilium.CiliumAgentImageTag))
g.Expect(status.Message).To(Equal(tc.statusMessage))

g.Expect(helmM.ApplyCalledWith).To(HaveLen(2))

firstCallArgs := helmM.ApplyCalledWith[0]
g.Expect(firstCallArgs.Chart).To(Equal(cilium.ChartCilium))
g.Expect(firstCallArgs.State).To(Equal(helm.StateUpgradeOnlyOrDeleted(networkCfg.GetEnabled())))
l2announcements, ok := firstCallArgs.Values["l2announcements"].(map[string]any)
g.Expect(ok).To(BeTrue())
g.Expect(l2announcements["enabled"]).To(Equal(lbCfg.GetL2Mode()))
bgpControlPlane, ok := firstCallArgs.Values["bgpControlPlane"].(map[string]any)
g.Expect(ok).To(BeTrue())
g.Expect(bgpControlPlane["enabled"]).To(Equal(lbCfg.GetBGPMode()))

secondCallArgs := helmM.ApplyCalledWith[1]
g.Expect(secondCallArgs.Chart).To(Equal(cilium.ChartCiliumLoadBalancer))
g.Expect(secondCallArgs.State).To(Equal(helm.StatePresent))
validateLoadBalancerValues(t, secondCallArgs.Values, lbCfg)

// check if cilium-operator and cilium daemonset are restarted
deployment, err := clientset.AppsV1().Deployments("kube-system").Get(context.Background(), "cilium-operator", metav1.GetOptions{})
g.Expect(err).ToNot(HaveOccurred())
Expand All @@ -201,3 +247,35 @@ func TestLoadBalancerEnabled(t *testing.T) {
})
}
}

func validateLoadBalancerValues(t *testing.T, values map[string]interface{}, lbCfg types.LoadBalancer) {
g := NewWithT(t)

l2, ok := values["l2"].(map[string]any)
g.Expect(ok).To(BeTrue())
g.Expect(l2["enabled"]).To(Equal(lbCfg.GetL2Mode()))
g.Expect(l2["interfaces"]).To(Equal(lbCfg.GetL2Interfaces()))

ipPool, ok := values["ipPool"].(map[string]any)
g.Expect(ok).To(BeTrue())
cidrs, ok := ipPool["cidrs"].([]map[string]any)
g.Expect(ok).To(BeTrue())
g.Expect(cidrs).To(HaveLen(len(lbCfg.GetIPRanges()) + len(lbCfg.GetCIDRs())))
for _, cidr := range lbCfg.GetCIDRs() {
g.Expect(cidrs).To(ContainElement(map[string]any{"cidr": cidr}))
}
for _, ipRange := range lbCfg.GetIPRanges() {
g.Expect(cidrs).To(ContainElement(map[string]any{"start": ipRange.Start, "stop": ipRange.Stop}))
}

bgp, ok := values["bgp"].(map[string]any)
g.Expect(ok).To(BeTrue())
g.Expect(bgp["enabled"]).To(Equal(lbCfg.GetBGPMode()))
g.Expect(bgp["localASN"]).To(Equal(lbCfg.GetBGPLocalASN()))
neighbors, ok := bgp["neighbors"].([]map[string]any)
g.Expect(ok).To(BeTrue())
g.Expect(neighbors).To(HaveLen(1))
g.Expect(neighbors[0]["peerAddress"]).To(Equal(lbCfg.GetBGPPeerAddress()))
g.Expect(neighbors[0]["peerASN"]).To(Equal(lbCfg.GetBGPPeerASN()))
g.Expect(neighbors[0]["peerPort"]).To(Equal(lbCfg.GetBGPPeerPort()))
}

0 comments on commit b33c2fe

Please sign in to comment.