From 723e36989c65289676fc546baeed1df4bca5ceaf Mon Sep 17 00:00:00 2001 From: Angelos Kolaitis Date: Thu, 16 May 2024 16:41:10 +0300 Subject: [PATCH] Group feature implementations in a swappable interface (#417) * Move features to subpackages * Group features behind a main implementation --- src/k8s/pkg/k8sd/controllers/feature.go | 14 ++-- src/k8s/pkg/k8sd/features/cilium/chart.go | 42 ++++++++++++ .../{feature_gateway.go => cilium/gateway.go} | 5 +- .../{feature_ingress.go => cilium/ingress.go} | 3 +- .../loadbalancer.go} | 3 +- .../{feature_network.go => cilium/network.go} | 5 +- src/k8s/pkg/k8sd/features/coredns/chart.go | 22 +++++++ .../{feature_dns.go => coredns/coredns.go} | 11 ++-- src/k8s/pkg/k8sd/features/features.go | 51 --------------- src/k8s/pkg/k8sd/features/images.go | 16 ----- .../k8sd/features/implementation_default.go | 23 +++++++ src/k8s/pkg/k8sd/features/interface.go | 65 +++++++++++++++++++ src/k8s/pkg/k8sd/features/localpv/chart.go | 22 +++++++ .../localpv.go} | 13 ++-- .../pkg/k8sd/features/metrics-server/chart.go | 22 +++++++ .../metrics_server.go} | 9 ++- .../metrics_server_test.go} | 6 +- 17 files changed, 227 insertions(+), 105 deletions(-) create mode 100644 src/k8s/pkg/k8sd/features/cilium/chart.go rename src/k8s/pkg/k8sd/features/{feature_gateway.go => cilium/gateway.go} (86%) rename src/k8s/pkg/k8sd/features/{feature_ingress.go => cilium/ingress.go} (94%) rename src/k8s/pkg/k8sd/features/{feature_loadbalancer.go => cilium/loadbalancer.go} (97%) rename src/k8s/pkg/k8sd/features/{feature_network.go => cilium/network.go} (96%) create mode 100644 src/k8s/pkg/k8sd/features/coredns/chart.go rename src/k8s/pkg/k8sd/features/{feature_dns.go => coredns/coredns.go} (87%) delete mode 100644 src/k8s/pkg/k8sd/features/features.go delete mode 100644 src/k8s/pkg/k8sd/features/images.go create mode 100644 src/k8s/pkg/k8sd/features/implementation_default.go create mode 100644 src/k8s/pkg/k8sd/features/interface.go create mode 100644 src/k8s/pkg/k8sd/features/localpv/chart.go rename src/k8s/pkg/k8sd/features/{feature_local_storage.go => localpv/localpv.go} (74%) create mode 100644 src/k8s/pkg/k8sd/features/metrics-server/chart.go rename src/k8s/pkg/k8sd/features/{feature_metrics_server.go => metrics-server/metrics_server.go} (70%) rename src/k8s/pkg/k8sd/features/{feature_metrics_server_test.go => metrics-server/metrics_server_test.go} (86%) diff --git a/src/k8s/pkg/k8sd/controllers/feature.go b/src/k8s/pkg/k8sd/controllers/feature.go index e5db2f239..1bd6ea086 100644 --- a/src/k8s/pkg/k8sd/controllers/feature.go +++ b/src/k8s/pkg/k8sd/controllers/feature.go @@ -73,31 +73,31 @@ func (c *FeatureController) Run(ctx context.Context, getClusterConfig func(conte c.waitReady() go c.reconcileLoop(ctx, getClusterConfig, "network", c.triggerNetworkCh, c.reconciledNetworkCh, func(cfg types.ClusterConfig) error { - return features.ApplyNetwork(ctx, c.snap, cfg.Network) + return features.Implementation.ApplyNetwork(ctx, c.snap, cfg.Network) }) go c.reconcileLoop(ctx, getClusterConfig, "gateway", c.triggerGatewayCh, c.reconciledGatewayCh, func(cfg types.ClusterConfig) error { - return features.ApplyGateway(ctx, c.snap, cfg.Gateway, cfg.Network) + return features.Implementation.ApplyGateway(ctx, c.snap, cfg.Gateway, cfg.Network) }) go c.reconcileLoop(ctx, getClusterConfig, "ingress", c.triggerIngressCh, c.reconciledIngressCh, func(cfg types.ClusterConfig) error { - return features.ApplyIngress(ctx, c.snap, cfg.Ingress, cfg.Network) + return features.Implementation.ApplyIngress(ctx, c.snap, cfg.Ingress, cfg.Network) }) go c.reconcileLoop(ctx, getClusterConfig, "load balancer", c.triggerLoadBalancerCh, c.reconciledLoadBalancerCh, func(cfg types.ClusterConfig) error { - return features.ApplyLoadBalancer(ctx, c.snap, cfg.LoadBalancer, cfg.Network) + return features.Implementation.ApplyLoadBalancer(ctx, c.snap, cfg.LoadBalancer, cfg.Network) }) go c.reconcileLoop(ctx, getClusterConfig, "local storage", c.triggerLocalStorageCh, c.reconciledLocalStorageCh, func(cfg types.ClusterConfig) error { - return features.ApplyLocalStorage(ctx, c.snap, cfg.LocalStorage) + return features.Implementation.ApplyLocalStorage(ctx, c.snap, cfg.LocalStorage) }) go c.reconcileLoop(ctx, getClusterConfig, "metrics server", c.triggerMetricsServerCh, c.reconciledMetricsServerCh, func(cfg types.ClusterConfig) error { - return features.ApplyMetricsServer(ctx, c.snap, cfg.MetricsServer) + return features.Implementation.ApplyMetricsServer(ctx, c.snap, cfg.MetricsServer) }) go c.reconcileLoop(ctx, getClusterConfig, "DNS", c.triggerDNSCh, c.reconciledDNSCh, func(cfg types.ClusterConfig) error { - if dnsIP, err := features.ApplyDNS(ctx, c.snap, cfg.DNS, cfg.Kubelet); err != nil { + if dnsIP, err := features.Implementation.ApplyDNS(ctx, c.snap, cfg.DNS, cfg.Kubelet); err != nil { return fmt.Errorf("failed to apply DNS configuration: %w", err) } else if dnsIP != "" { if err := notifyDNSChangedIP(ctx, dnsIP); err != nil { diff --git a/src/k8s/pkg/k8sd/features/cilium/chart.go b/src/k8s/pkg/k8sd/features/cilium/chart.go new file mode 100644 index 000000000..66ea2a64d --- /dev/null +++ b/src/k8s/pkg/k8sd/features/cilium/chart.go @@ -0,0 +1,42 @@ +package cilium + +import ( + "path" + + "github.com/canonical/k8s/pkg/client/helm" +) + +var ( + // chartCilium represents manifests to deploy Cilium. + chartCilium = helm.InstallableChart{ + Name: "ck-network", + Namespace: "kube-system", + ManifestPath: path.Join("charts", "cilium-1.15.2.tgz"), + } + + // chartCiliumLoadBalancer represents manifests to deploy Cilium LoadBalancer resources. + chartCiliumLoadBalancer = helm.InstallableChart{ + Name: "ck-loadbalancer", + Namespace: "kube-system", + ManifestPath: path.Join("charts", "ck-loadbalancer"), + } + + // chartGateway represents manifests to deploy Gateway API CRDs. + chartGateway = helm.InstallableChart{ + Name: "ck-gateway", + Namespace: "kube-system", + ManifestPath: path.Join("charts", "gateway-api-1.0.0.tgz"), + } + + // ciliumAgentImageRepo represents the image to use for cilium-agent. + ciliumAgentImageRepo = "ghcr.io/canonical/cilium" + + // ciliumAgentImageTag is the tag to use for the cilium-agent image. + ciliumAgentImageTag = "1.15.2-ck1" + + // ciliumOperatorImageRepo is the image to use for cilium-operator. + ciliumOperatorImageRepository = "ghcr.io/canonical/cilium-operator" + + // ciliumOperatorImageTag is the tag to use for the cilium-operator image. + ciliumOperatorImageTag = "1.15.2-ck1" +) diff --git a/src/k8s/pkg/k8sd/features/feature_gateway.go b/src/k8s/pkg/k8sd/features/cilium/gateway.go similarity index 86% rename from src/k8s/pkg/k8sd/features/feature_gateway.go rename to src/k8s/pkg/k8sd/features/cilium/gateway.go index 9414e2c26..3c91a125d 100644 --- a/src/k8s/pkg/k8sd/features/feature_gateway.go +++ b/src/k8s/pkg/k8sd/features/cilium/gateway.go @@ -1,4 +1,4 @@ -package features +package cilium import ( "context" @@ -9,7 +9,6 @@ import ( "github.com/canonical/k8s/pkg/snap" ) -// ApplyGateway is used to configure the gateway feature on Canonical Kubernetes. // ApplyGateway assumes that the managed Cilium CNI is already installed on the cluster. It will fail if that is not the case. // ApplyGateway will deploy the Gateway API CRDs on the cluster and enable the GatewayAPI controllers on Cilium, when gateway.Enabled is true. // ApplyGateway will remove the Gateway API CRDs from the cluster and disable the GatewayAPI controllers on Cilium, when gateway.Enabled is false. @@ -18,7 +17,7 @@ import ( func ApplyGateway(ctx context.Context, snap snap.Snap, gateway types.Gateway, network types.Network) error { m := snap.HelmClient() - if _, err := m.Apply(ctx, chartCiliumGateway, helm.StatePresentOrDeleted(gateway.GetEnabled()), nil); err != nil { + if _, err := m.Apply(ctx, chartGateway, helm.StatePresentOrDeleted(gateway.GetEnabled()), nil); err != nil { return fmt.Errorf("failed to install Gateway API CRDs: %w", err) } diff --git a/src/k8s/pkg/k8sd/features/feature_ingress.go b/src/k8s/pkg/k8sd/features/cilium/ingress.go similarity index 94% rename from src/k8s/pkg/k8sd/features/feature_ingress.go rename to src/k8s/pkg/k8sd/features/cilium/ingress.go index 48d1a9c2a..604c22490 100644 --- a/src/k8s/pkg/k8sd/features/feature_ingress.go +++ b/src/k8s/pkg/k8sd/features/cilium/ingress.go @@ -1,4 +1,4 @@ -package features +package cilium import ( "context" @@ -9,7 +9,6 @@ import ( "github.com/canonical/k8s/pkg/snap" ) -// ApplyIngress is used to configure the ingress controller feature on Canonical Kubernetes. // ApplyIngress assumes that the managed Cilium CNI is already installed on the cluster. It will fail if that is not the case. // ApplyIngress will enable Cilium's ingress controller when ingress.Enabled is true. // ApplyIngress will disable Cilium's ingress controller when ingress.Disabled is false. diff --git a/src/k8s/pkg/k8sd/features/feature_loadbalancer.go b/src/k8s/pkg/k8sd/features/cilium/loadbalancer.go similarity index 97% rename from src/k8s/pkg/k8sd/features/feature_loadbalancer.go rename to src/k8s/pkg/k8sd/features/cilium/loadbalancer.go index 3595fd01b..e3c7cfbbe 100644 --- a/src/k8s/pkg/k8sd/features/feature_loadbalancer.go +++ b/src/k8s/pkg/k8sd/features/cilium/loadbalancer.go @@ -1,4 +1,4 @@ -package features +package cilium import ( "context" @@ -10,7 +10,6 @@ import ( "github.com/canonical/k8s/pkg/utils/control" ) -// ApplyLoadBalancer is used to configure the load-balancer feature on Canonical Kubernetes. // ApplyLoadBalancer assumes that the managed Cilium CNI is already installed on the cluster. It will fail if that is not the case. // ApplyLoadBalancer will configure Cilium to enable L2 or BGP mode, and deploy necessary CRs for announcing the LoadBalancer external IPs when loadbalancer.Enabled is true. // ApplyLoadBalancer will disable L2 and BGP on Cilium, and remove any previously created CRs when loadbalancer.Enabled is false. diff --git a/src/k8s/pkg/k8sd/features/feature_network.go b/src/k8s/pkg/k8sd/features/cilium/network.go similarity index 96% rename from src/k8s/pkg/k8sd/features/feature_network.go rename to src/k8s/pkg/k8sd/features/cilium/network.go index 5cc08b3ed..f116eb6b8 100644 --- a/src/k8s/pkg/k8sd/features/feature_network.go +++ b/src/k8s/pkg/k8sd/features/cilium/network.go @@ -1,4 +1,4 @@ -package features +package cilium import ( "context" @@ -14,7 +14,6 @@ import ( "github.com/canonical/k8s/pkg/utils/control" ) -// ApplyNetwork is used to configure the CNI feature on Canonical Kubernetes. // ApplyNetwork will deploy Cilium when cfg.Enabled is true. // ApplyNetwork will remove Cilium when cfg.Enabled is false. // ApplyNetwork requires that bpf and cgroups2 are already mounted and available when running under strict snap confinement. If they are not, it will fail (since Cilium will not have the required permissions to mount them). @@ -53,7 +52,7 @@ func ApplyNetwork(ctx context.Context, snap snap.Snap, cfg types.Network) error values := map[string]any{ "image": map[string]any{ - "repository": ciliumAgentImageRepository, + "repository": ciliumAgentImageRepo, "tag": ciliumAgentImageTag, "useDigest": false, }, diff --git a/src/k8s/pkg/k8sd/features/coredns/chart.go b/src/k8s/pkg/k8sd/features/coredns/chart.go new file mode 100644 index 000000000..2a893bd30 --- /dev/null +++ b/src/k8s/pkg/k8sd/features/coredns/chart.go @@ -0,0 +1,22 @@ +package coredns + +import ( + "path" + + "github.com/canonical/k8s/pkg/client/helm" +) + +var ( + // chartCoreDNS represents manifests to deploy CoreDNS. + chart = helm.InstallableChart{ + Name: "ck-dns", + Namespace: "kube-system", + ManifestPath: path.Join("charts", "coredns-1.29.0.tgz"), + } + + // imageRepo is the image to use for CoreDNS. + imageRepo = "ghcr.io/canonical/coredns" + + // imageTag is the tag to use for the CoreDNS image. + imageTag = "1.11.1-ck4" +) diff --git a/src/k8s/pkg/k8sd/features/feature_dns.go b/src/k8s/pkg/k8sd/features/coredns/coredns.go similarity index 87% rename from src/k8s/pkg/k8sd/features/feature_dns.go rename to src/k8s/pkg/k8sd/features/coredns/coredns.go index 50a7d7a4b..33ce60d75 100644 --- a/src/k8s/pkg/k8sd/features/feature_dns.go +++ b/src/k8s/pkg/k8sd/features/coredns/coredns.go @@ -1,4 +1,4 @@ -package features +package coredns import ( "context" @@ -10,7 +10,6 @@ import ( "github.com/canonical/k8s/pkg/snap" ) -// ApplyDNS is used to configure the DNS feature on Canonical Kubernetes. // ApplyDNS manages the deployment of CoreDNS, with customization options from dns and kubelet, which are retrieved from the cluster configuration. // ApplyDNS will uninstall CoreDNS from the cluster if dns.Enabled is false. // ApplyDNS will install or refresh CoreDNS if dns.Enabled is true. @@ -20,7 +19,7 @@ func ApplyDNS(ctx context.Context, snap snap.Snap, dns types.DNS, kubelet types. m := snap.HelmClient() if !dns.GetEnabled() { - if _, err := m.Apply(ctx, chartCoreDNS, helm.StateDeleted, nil); err != nil { + if _, err := m.Apply(ctx, chart, helm.StateDeleted, nil); err != nil { return "", fmt.Errorf("failed to uninstall coredns: %w", err) } return "", nil @@ -28,8 +27,8 @@ func ApplyDNS(ctx context.Context, snap snap.Snap, dns types.DNS, kubelet types. values := map[string]any{ "image": map[string]any{ - "repository": dnsImageRepository, - "tag": dnsImageTag, + "repository": imageRepo, + "tag": imageTag, }, "service": map[string]any{ "name": "coredns", @@ -64,7 +63,7 @@ func ApplyDNS(ctx context.Context, snap snap.Snap, dns types.DNS, kubelet types. }, } - if _, err := m.Apply(ctx, chartCoreDNS, helm.StatePresent, values); err != nil { + if _, err := m.Apply(ctx, chart, helm.StatePresent, values); err != nil { return "", fmt.Errorf("failed to apply coredns: %w", err) } diff --git a/src/k8s/pkg/k8sd/features/features.go b/src/k8s/pkg/k8sd/features/features.go deleted file mode 100644 index cde037e21..000000000 --- a/src/k8s/pkg/k8sd/features/features.go +++ /dev/null @@ -1,51 +0,0 @@ -package features - -import ( - "path" - - "github.com/canonical/k8s/pkg/client/helm" -) - -var ( - // chartCoreDNS is manifests for the built-in DNS feature, powered by CoreDNS. - chartCoreDNS = helm.InstallableChart{ - Name: "ck-dns", - Namespace: "kube-system", - ManifestPath: path.Join("charts", "coredns-1.29.0.tgz"), - } - - // chartCilium is manifests for the built-in CNI feature, powered by Cilium. - chartCilium = helm.InstallableChart{ - Name: "ck-network", - Namespace: "kube-system", - ManifestPath: path.Join("charts", "cilium-1.15.2.tgz"), - } - - // chartCiliumLoadBalancer is manifests for the built-in load-balancer feature, powered by Cilium. - chartCiliumLoadBalancer = helm.InstallableChart{ - Name: "ck-loadbalancer", - Namespace: "kube-system", - ManifestPath: path.Join("charts", "ck-loadbalancer"), - } - - // chartCiliumGateway is manifests for the built-in gateway feature, powered by Cilium. - chartCiliumGateway = helm.InstallableChart{ - Name: "ck-gateway", - Namespace: "kube-system", - ManifestPath: path.Join("charts", "gateway-api-1.0.0.tgz"), - } - - // chartLocalStorage is manifests for the built-in local storage feature, powered by Rawfile LocalPV CSI. - chartLocalStorage = helm.InstallableChart{ - Name: "ck-storage", - Namespace: "kube-system", - ManifestPath: path.Join("charts", "rawfile-csi-0.8.0.tgz"), - } - - // chartMetricsServer is manifests for the built-in metrics-server feature, powered by the upstream metrics-server. - chartMetricsServer = helm.InstallableChart{ - Name: "metrics-server", - Namespace: "kube-system", - ManifestPath: path.Join("charts", "metrics-server-3.12.0.tgz"), - } -) diff --git a/src/k8s/pkg/k8sd/features/images.go b/src/k8s/pkg/k8sd/features/images.go deleted file mode 100644 index 14fbbd9cd..000000000 --- a/src/k8s/pkg/k8sd/features/images.go +++ /dev/null @@ -1,16 +0,0 @@ -package features - -const dnsImageRepository = "ghcr.io/canonical/coredns" -const dnsImageTag = "1.11.1-ck4" - -const ciliumAgentImageRepository = "ghcr.io/canonical/cilium" -const ciliumAgentImageTag = "1.15.2-ck1" - -const ciliumOperatorImageRepository = "ghcr.io/canonical/cilium-operator" -const ciliumOperatorImageTag = "1.15.2-ck1" - -const storageImageRepository = "ghcr.io/canonical/rawfile-localpv" -const storageImageTag = "0.8.0-ck5" - -const metricsServerImageRepository = "ghcr.io/canonical/metrics-server" -const metricsServerImageTag = "0.7.0-ck0" diff --git a/src/k8s/pkg/k8sd/features/implementation_default.go b/src/k8s/pkg/k8sd/features/implementation_default.go new file mode 100644 index 000000000..aac2d977a --- /dev/null +++ b/src/k8s/pkg/k8sd/features/implementation_default.go @@ -0,0 +1,23 @@ +package features + +import ( + "github.com/canonical/k8s/pkg/k8sd/features/cilium" + "github.com/canonical/k8s/pkg/k8sd/features/coredns" + "github.com/canonical/k8s/pkg/k8sd/features/localpv" + metrics_server "github.com/canonical/k8s/pkg/k8sd/features/metrics-server" +) + +// Default implements the Canonical Kubernetes built-in features. +// Cilium is used for networking (network + load-balancer + ingress + gateway). +// CoreDNS is used for DNS. +// MetricsServer is used for metrics-server. +// LocalPV Rawfile CSI is used for local-storage. +var Implementation Interface = &implementation{ + applyDNS: coredns.ApplyDNS, + applyNetwork: cilium.ApplyNetwork, + applyLoadBalancer: cilium.ApplyLoadBalancer, + applyIngress: cilium.ApplyIngress, + applyGateway: cilium.ApplyGateway, + applyMetricsServer: metrics_server.ApplyMetricsServer, + applyLocalStorage: localpv.ApplyLocalStorage, +} diff --git a/src/k8s/pkg/k8sd/features/interface.go b/src/k8s/pkg/k8sd/features/interface.go new file mode 100644 index 000000000..f72fb05f6 --- /dev/null +++ b/src/k8s/pkg/k8sd/features/interface.go @@ -0,0 +1,65 @@ +package features + +import ( + "context" + + "github.com/canonical/k8s/pkg/k8sd/types" + "github.com/canonical/k8s/pkg/snap" +) + +// Interface abstracts the management of built-in Canonical Kubernetes features. +type Interface interface { + // ApplyDNS is used to configure the DNS feature on Canonical Kubernetes. + ApplyDNS(context.Context, snap.Snap, types.DNS, types.Kubelet) (string, error) + // ApplyNetwork is used to configure the network feature on Canonical Kubernetes. + ApplyNetwork(context.Context, snap.Snap, types.Network) error + // ApplyLoadBalancer is used to configure the load-balancer feature on Canonical Kubernetes. + ApplyLoadBalancer(context.Context, snap.Snap, types.LoadBalancer, types.Network) error + // ApplyIngress is used to configure the ingress controller feature on Canonical Kubernetes. + ApplyIngress(context.Context, snap.Snap, types.Ingress, types.Network) error + // ApplyGateway is used to configure the gateway feature on Canonical Kubernetes. + ApplyGateway(context.Context, snap.Snap, types.Gateway, types.Network) error + // ApplyMetricsServer is used to configure the metrics-server feature on Canonical Kubernetes. + ApplyMetricsServer(context.Context, snap.Snap, types.MetricsServer) error + // ApplyLocalStorage is used to configure the Local Storage feature on Canonical Kubernetes. + ApplyLocalStorage(context.Context, snap.Snap, types.LocalStorage) error +} + +// implementation implements Interface. +type implementation struct { + applyDNS func(context.Context, snap.Snap, types.DNS, types.Kubelet) (string, error) + applyNetwork func(context.Context, snap.Snap, types.Network) error + applyLoadBalancer func(context.Context, snap.Snap, types.LoadBalancer, types.Network) error + applyIngress func(context.Context, snap.Snap, types.Ingress, types.Network) error + applyGateway func(context.Context, snap.Snap, types.Gateway, types.Network) error + applyMetricsServer func(context.Context, snap.Snap, types.MetricsServer) error + applyLocalStorage func(context.Context, snap.Snap, types.LocalStorage) error +} + +func (i *implementation) ApplyDNS(ctx context.Context, snap snap.Snap, dns types.DNS, kubelet types.Kubelet) (string, error) { + return i.applyDNS(ctx, snap, dns, kubelet) +} + +func (i *implementation) ApplyNetwork(ctx context.Context, snap snap.Snap, cfg types.Network) error { + return i.applyNetwork(ctx, snap, cfg) +} + +func (i *implementation) ApplyLoadBalancer(ctx context.Context, snap snap.Snap, loadbalancer types.LoadBalancer, network types.Network) error { + return i.applyLoadBalancer(ctx, snap, loadbalancer, network) +} + +func (i *implementation) ApplyIngress(ctx context.Context, snap snap.Snap, ingress types.Ingress, network types.Network) error { + return i.applyIngress(ctx, snap, ingress, network) +} + +func (i *implementation) ApplyGateway(ctx context.Context, snap snap.Snap, gateway types.Gateway, network types.Network) error { + return i.applyGateway(ctx, snap, gateway, network) +} + +func (i *implementation) ApplyMetricsServer(ctx context.Context, snap snap.Snap, cfg types.MetricsServer) error { + return i.applyMetricsServer(ctx, snap, cfg) +} + +func (i *implementation) ApplyLocalStorage(ctx context.Context, snap snap.Snap, cfg types.LocalStorage) error { + return i.applyLocalStorage(ctx, snap, cfg) +} diff --git a/src/k8s/pkg/k8sd/features/localpv/chart.go b/src/k8s/pkg/k8sd/features/localpv/chart.go new file mode 100644 index 000000000..c704127cb --- /dev/null +++ b/src/k8s/pkg/k8sd/features/localpv/chart.go @@ -0,0 +1,22 @@ +package localpv + +import ( + "path" + + "github.com/canonical/k8s/pkg/client/helm" +) + +var ( + // chart represents manifests to deploy Rawfile LocalPV CSI. + chart = helm.InstallableChart{ + Name: "ck-storage", + Namespace: "kube-system", + ManifestPath: path.Join("charts", "rawfile-csi-0.8.0.tgz"), + } + + // imageRepo is the image to use for Rawfile LocalPV CSI. + imageRepo = "ghcr.io/canonical/rawfile-localpv" + + // imageTag is the image tag to use. + imageTag = "0.8.0-ck5" +) diff --git a/src/k8s/pkg/k8sd/features/feature_local_storage.go b/src/k8s/pkg/k8sd/features/localpv/localpv.go similarity index 74% rename from src/k8s/pkg/k8sd/features/feature_local_storage.go rename to src/k8s/pkg/k8sd/features/localpv/localpv.go index 940370381..a4a1538c2 100644 --- a/src/k8s/pkg/k8sd/features/feature_local_storage.go +++ b/src/k8s/pkg/k8sd/features/localpv/localpv.go @@ -1,4 +1,4 @@ -package features +package localpv import ( "context" @@ -8,7 +8,6 @@ import ( "github.com/canonical/k8s/pkg/snap" ) -// ApplyLocalStorage is used to configure the Local Storage feature on Canonical Kubernetes. // ApplyLocalStorage deploys the rawfile-localpv CSI driver on the cluster based on the given configuration, when cfg.Enabled is true. // ApplyLocalStorage removes the rawfile-localpv when cfg.Enabled is false. // ApplyLocalStorage returns an error if anything fails. @@ -27,14 +26,14 @@ func ApplyLocalStorage(ctx context.Context, snap snap.Snap, cfg types.LocalStora "controller": map[string]any{ "csiDriverArgs": []string{"--args", "rawfile", "csi-driver", "--disable-metrics"}, "image": map[string]any{ - "repository": storageImageRepository, - "tag": storageImageTag, + "repository": imageRepo, + "tag": imageTag, }, }, "node": map[string]any{ "image": map[string]any{ - "repository": storageImageRepository, - "tag": storageImageTag, + "repository": imageRepo, + "tag": imageTag, }, "storage": map[string]any{ "path": cfg.GetLocalPath(), @@ -42,6 +41,6 @@ func ApplyLocalStorage(ctx context.Context, snap snap.Snap, cfg types.LocalStora }, } - _, err := m.Apply(ctx, chartLocalStorage, helm.StatePresentOrDeleted(cfg.GetEnabled()), values) + _, err := m.Apply(ctx, chart, helm.StatePresentOrDeleted(cfg.GetEnabled()), values) return err } diff --git a/src/k8s/pkg/k8sd/features/metrics-server/chart.go b/src/k8s/pkg/k8sd/features/metrics-server/chart.go new file mode 100644 index 000000000..df25d9562 --- /dev/null +++ b/src/k8s/pkg/k8sd/features/metrics-server/chart.go @@ -0,0 +1,22 @@ +package metrics_server + +import ( + "path" + + "github.com/canonical/k8s/pkg/client/helm" +) + +var ( + // chart represents manifests to deploy metrics-server. + chart = helm.InstallableChart{ + Name: "metrics-server", + Namespace: "kube-system", + ManifestPath: path.Join("charts", "metrics-server-3.12.0.tgz"), + } + + // imageRepo is the image to use for metrics-server. + imageRepo = "ghcr.io/canonical/metrics-server" + + // imageTag is the image tag to use for metrics-server. + imageTag = "0.7.0-ck0" +) diff --git a/src/k8s/pkg/k8sd/features/feature_metrics_server.go b/src/k8s/pkg/k8sd/features/metrics-server/metrics_server.go similarity index 70% rename from src/k8s/pkg/k8sd/features/feature_metrics_server.go rename to src/k8s/pkg/k8sd/features/metrics-server/metrics_server.go index 41bb376c8..96d6ff89f 100644 --- a/src/k8s/pkg/k8sd/features/feature_metrics_server.go +++ b/src/k8s/pkg/k8sd/features/metrics-server/metrics_server.go @@ -1,4 +1,4 @@ -package features +package metrics_server import ( "context" @@ -8,7 +8,6 @@ import ( "github.com/canonical/k8s/pkg/snap" ) -// ApplyMetricsServer is used to configure the metrics-server feature on Canonical Kubernetes. // ApplyMetricsServer deploys metrics-server when cfg.Enabled is true. // ApplyMetricsServer removes metrics-server when cfg.Enabled is false. // ApplyMetricsServer returns an error if anything fails. @@ -17,8 +16,8 @@ func ApplyMetricsServer(ctx context.Context, snap snap.Snap, cfg types.MetricsSe values := map[string]any{ "image": map[string]any{ - "repository": metricsServerImageRepository, - "tag": metricsServerImageTag, + "repository": imageRepo, + "tag": imageTag, }, "securityContext": map[string]any{ // ROCKs with Pebble as the entrypoint do not work with this option. @@ -26,6 +25,6 @@ func ApplyMetricsServer(ctx context.Context, snap snap.Snap, cfg types.MetricsSe }, } - _, err := m.Apply(ctx, chartMetricsServer, helm.StatePresentOrDeleted(cfg.GetEnabled()), values) + _, err := m.Apply(ctx, chart, helm.StatePresentOrDeleted(cfg.GetEnabled()), values) return err } diff --git a/src/k8s/pkg/k8sd/features/feature_metrics_server_test.go b/src/k8s/pkg/k8sd/features/metrics-server/metrics_server_test.go similarity index 86% rename from src/k8s/pkg/k8sd/features/feature_metrics_server_test.go rename to src/k8s/pkg/k8sd/features/metrics-server/metrics_server_test.go index 45f32be6b..855bdd7bb 100644 --- a/src/k8s/pkg/k8sd/features/feature_metrics_server_test.go +++ b/src/k8s/pkg/k8sd/features/metrics-server/metrics_server_test.go @@ -1,4 +1,4 @@ -package features_test +package metrics_server_test import ( "context" @@ -6,7 +6,7 @@ import ( "github.com/canonical/k8s/pkg/client/helm" helmmock "github.com/canonical/k8s/pkg/client/helm/mock" - "github.com/canonical/k8s/pkg/k8sd/features" + metrics_server "github.com/canonical/k8s/pkg/k8sd/features/metrics-server" "github.com/canonical/k8s/pkg/k8sd/types" snapmock "github.com/canonical/k8s/pkg/snap/mock" "github.com/canonical/k8s/pkg/utils" @@ -43,7 +43,7 @@ func TestApplyMetricsServer(t *testing.T) { }, } - err := features.ApplyMetricsServer(context.Background(), s, tc.config) + err := metrics_server.ApplyMetricsServer(context.Background(), s, tc.config) g.Expect(err).ToNot(HaveOccurred()) g.Expect(h.ApplyCalledWith).To(ConsistOf(SatisfyAll(