Skip to content

Commit

Permalink
feat(k8sd): introduce feature packages and update feature apply funct…
Browse files Browse the repository at this point in the history
…ions

- Added the FeatureManifest struct that contains the required charts and images for the feature.
- Features are updated to use feature manifests when reconciling through the feature controller.
- Implementation modules under `features` are updated to contain sub modules per feature.
- Values handling is separated from the `Apply` functions and is performed via helper functions instead.
- Introduced helper `Values` types and related functions for merging values together using mergo.
  • Loading branch information
berkayoz committed Mar 6, 2025
1 parent 4883123 commit 2695bc6
Show file tree
Hide file tree
Showing 81 changed files with 2,762 additions and 1,536 deletions.
40 changes: 0 additions & 40 deletions src/k8s/pkg/k8sd/features/calico/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,7 @@ package calico

import (
"embed"

"github.com/canonical/k8s/pkg/client/helm"
)

//go:embed all:charts
var ChartFS embed.FS

var (
// ChartCalico represents manifests to deploy Calico.
ChartCalico = helm.InstallableChart{
Name: "tigera-operator",
Version: "v3.28.0",
InstallName: "ck-network",
InstallNamespace: "tigera-operator",
}

// Note: Tigera is the company behind Calico and the tigera-operator is the operator for Calico.
// TODO: use ROCKs instead of upstream
// imageRepo represents the repo to fetch the Calico CNI images.
imageRepo = "ghcr.io/canonical/k8s-snap"

// calicoImageRepo represents the repo to fetch the calico images.
calicoImageRepo = "ghcr.io/canonical/k8s-snap/calico"
// CalicoTag represents the tag to use for the calico images.
CalicoTag = "v3.28.0"

// tigeraOperatorImage represents the image to fetch for calico.
tigeraOperatorImage = "tigera/operator"

// tigeraOperatorVersion is the version to use for the tigera-operator image.
tigeraOperatorVersion = "v1.34.0"

// calicoCtlImage represents the image to fetch for calicoctl.
// TODO: use ROCKs instead of upstream
calicoCtlImage = "ghcr.io/canonical/k8s-snap/calico/ctl"
// calicoCtlTag represents the tag to use for the calicoctl image.
calicoCtlTag = "v3.28.0"

// defaultEncapsulation represents the default defaultEncapsulation method to use for Calico.
defaultEncapsulation = "VXLAN"

// defaultAPIServerEnabled determines if the Calico API server should be enabled.
defaultAPIServerEnabled = false
)
143 changes: 0 additions & 143 deletions src/k8s/pkg/k8sd/features/calico/network.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package calico
package network

import (
"fmt"
Expand Down Expand Up @@ -63,11 +63,7 @@ func parseAutodetectionAnnotations(annotations types.Annotations, autodetectionM
}

func internalConfig(annotations types.Annotations) (config, error) {
c := config{
encapsulationV4: defaultEncapsulation,
encapsulationV6: defaultEncapsulation,
apiServerEnabled: defaultAPIServerEnabled,
}
c := config{}

if v, ok := annotations.Get(apiv1_annotations.AnnotationAPIServerEnabled); ok {
c.apiServerEnabled = v == "true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package calico
package network

import (
"testing"
Expand All @@ -19,8 +19,8 @@ func TestInternalConfig(t *testing.T) {
annotations: map[string]string{},
expectedConfig: config{
apiServerEnabled: false,
encapsulationV4: "VXLAN",
encapsulationV6: "VXLAN",
encapsulationV4: "",
encapsulationV6: "",
},
expectError: false,
},
Expand All @@ -33,7 +33,7 @@ func TestInternalConfig(t *testing.T) {
expectedConfig: config{
apiServerEnabled: true,
encapsulationV4: "IPIP",
encapsulationV6: "VXLAN",
encapsulationV6: "",
},
expectError: false,
},
Expand All @@ -53,7 +53,7 @@ func TestInternalConfig(t *testing.T) {
expectedConfig: config{
apiServerEnabled: false,
encapsulationV4: "VXLAN",
encapsulationV6: "VXLAN",
encapsulationV6: "",
},
expectError: false,
},
Expand All @@ -72,8 +72,8 @@ func TestInternalConfig(t *testing.T) {
},
expectedConfig: config{
apiServerEnabled: false,
encapsulationV4: "VXLAN",
encapsulationV6: "VXLAN",
encapsulationV4: "",
encapsulationV6: "",
autodetectionV4: map[string]any{
"cidrs": []string{"10.1.0.0/16", "2001:0db8::/32"},
},
Expand Down
47 changes: 47 additions & 0 deletions src/k8s/pkg/k8sd/features/calico/network/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package network

import (
"github.com/canonical/k8s/pkg/client/helm"
"github.com/canonical/k8s/pkg/k8sd/types"
)

var (
CalicoChartName = "tigera-operator"

CalicoImageName = "calico"
TigeraOperatorImageName = "tigera-operator"
CalicoCtlImageName = "calicoctl"
)

var manifest = types.FeatureManifest{
Name: "network",
Version: "1.0.0",
Charts: map[string]helm.InstallableChart{
CalicoChartName: {
Name: "tigera-operator",
Version: "v3.28.0",
InstallName: "ck-network",
InstallNamespace: "tigera-operator",
},
},

Images: map[string]types.Image{
"calico": {
Registry: "ghcr.io/canonical/k8s-snap",
Repository: "calico",
Tag: "v3.28.0",
},
"tigera-operator": {
Registry: "ghcr.io/canonical/k8s-snap",
Repository: "tigera/operator",
Tag: "v1.34.0",
},
"calicoctl": {
Registry: "ghcr.io/canonical/k8s-snap",
Repository: "calico/ctl",
Tag: "v3.28.0",
},
},
}

var FeatureNetwork types.Feature = manifest
Loading

0 comments on commit 2695bc6

Please sign in to comment.