Skip to content

Commit a339de2

Browse files
Add networking-calico and networking-cilium components (#56)
* Add networking-calico extension * Add networking-cilium extension * drop obsolete version file * address review feedback
1 parent 5ec0446 commit a339de2

19 files changed

Lines changed: 542 additions & 0 deletions

componentvector/components.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

componentvector/components.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ components:
22
- name: github.com/gardener/gardener
33
sourceRepository: https://github.com/gardener/gardener
44
version: v1.134.1
5+
- name: github.com/gardener/gardener-extension-networking-calico
6+
sourceRepository: https://github.com/gardener/gardener-extension-networking-calico
7+
version: v1.54.0
8+
- name: github.com/gardener/gardener-extension-networking-cilium
9+
sourceRepository: https://github.com/gardener/gardener-extension-networking-cilium
10+
version: v1.45.2
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package networking_calico
6+
7+
import (
8+
"embed"
9+
"path"
10+
11+
"github.com/gardener/gardener-landscape-kit/componentvector"
12+
"github.com/gardener/gardener-landscape-kit/pkg/components"
13+
"github.com/gardener/gardener-landscape-kit/pkg/utils/files"
14+
)
15+
16+
const (
17+
// ComponentDirectory is the garden component directory within the base components directory.
18+
ComponentDirectory = "gardener-extensions/networking-calico"
19+
)
20+
21+
var (
22+
// baseTemplateDir is the directory where the base templates are stored.
23+
baseTemplateDir = "templates/base"
24+
//go:embed templates/base
25+
baseTemplates embed.FS
26+
27+
// landscapeTemplateDir is the directory where the landscape templates are stored.
28+
landscapeTemplateDir = "templates/landscape"
29+
//go:embed templates/landscape
30+
landscapeTemplates embed.FS
31+
)
32+
33+
type component struct{}
34+
35+
// NewComponent creates a new garden component.
36+
func NewComponent() components.Interface {
37+
return &component{}
38+
}
39+
40+
// Name returns the component name.
41+
func (c *component) Name() string {
42+
return "networking-calico"
43+
}
44+
45+
// GenerateBase generates the component base directory.
46+
func (c *component) GenerateBase(options components.Options) error {
47+
for _, op := range []func(components.Options) error{
48+
writeBaseTemplateFiles,
49+
} {
50+
if err := op(options); err != nil {
51+
return err
52+
}
53+
}
54+
return nil
55+
}
56+
57+
// GenerateLandscape generates the component landscape directory.
58+
func (c *component) GenerateLandscape(options components.LandscapeOptions) error {
59+
for _, op := range []func(components.LandscapeOptions) error{
60+
writeLandscapeTemplateFiles,
61+
} {
62+
if err := op(options); err != nil {
63+
return err
64+
}
65+
}
66+
return nil
67+
}
68+
69+
func writeBaseTemplateFiles(opts components.Options) error {
70+
version, exists := opts.GetComponentVector().FindComponentVersion(componentvector.NameGardenerGardenerExtensionNetworkingCalico)
71+
if !exists {
72+
opts.GetLogger().Info("Component version not found in component vector, falling back to empty version", "component", componentvector.NameGardenerGardenerExtensionNetworkingCalico)
73+
}
74+
75+
objects, err := files.RenderTemplateFiles(baseTemplates, baseTemplateDir, map[string]any{
76+
"version": version,
77+
})
78+
if err != nil {
79+
return err
80+
}
81+
82+
return files.WriteObjectsToFilesystem(objects, opts.GetTargetPath(), path.Join(components.DirName, ComponentDirectory), opts.GetFilesystem())
83+
}
84+
85+
func writeLandscapeTemplateFiles(opts components.LandscapeOptions) error {
86+
var (
87+
relativeComponentPath = path.Join(components.DirName, ComponentDirectory)
88+
relativeRepoRoot = files.CalculatePathToComponentBase(opts.GetRelativeLandscapePath(), relativeComponentPath)
89+
)
90+
91+
objects, err := files.RenderTemplateFiles(landscapeTemplates, landscapeTemplateDir, map[string]any{
92+
"relativePathToBaseComponent": path.Join(relativeRepoRoot, opts.GetRelativeBasePath(), relativeComponentPath),
93+
"landscapeComponentPath": path.Join(opts.GetRelativeLandscapePath(), relativeComponentPath),
94+
})
95+
if err != nil {
96+
return err
97+
}
98+
99+
return files.WriteObjectsToFilesystem(objects, opts.GetTargetPath(), path.Join(components.DirName, ComponentDirectory), opts.GetFilesystem())
100+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package networking_calico_test
6+
7+
import (
8+
"github.com/go-logr/logr"
9+
. "github.com/onsi/ginkgo/v2"
10+
. "github.com/onsi/gomega"
11+
"github.com/spf13/afero"
12+
13+
"github.com/gardener/gardener-landscape-kit/pkg/apis/config/v1alpha1"
14+
"github.com/gardener/gardener-landscape-kit/pkg/cmd"
15+
generateoptions "github.com/gardener/gardener-landscape-kit/pkg/cmd/generate/options"
16+
"github.com/gardener/gardener-landscape-kit/pkg/components"
17+
networking_calico "github.com/gardener/gardener-landscape-kit/pkg/components/gardener-extensions/networking-calico"
18+
)
19+
20+
var _ = Describe("Component Generation", func() {
21+
var (
22+
fs afero.Afero
23+
cmdOpts *cmd.Options
24+
generateOpts *generateoptions.Options
25+
)
26+
27+
BeforeEach(func() {
28+
fs = afero.Afero{Fs: afero.NewMemMapFs()}
29+
cmdOpts = &cmd.Options{Log: logr.Discard()}
30+
generateOpts = &generateoptions.Options{
31+
TargetDirPath: "/repo/baseDir",
32+
Options: cmdOpts,
33+
}
34+
})
35+
36+
Describe("#GenerateBase", func() {
37+
var opts components.Options
38+
39+
BeforeEach(func() {
40+
var err error
41+
opts, err = components.NewOptions(generateOpts, fs)
42+
Expect(err).ToNot(HaveOccurred())
43+
})
44+
45+
It("should generate the component base", func() {
46+
component := networking_calico.NewComponent()
47+
Expect(component.GenerateBase(opts)).To(Succeed())
48+
49+
content, err := fs.ReadFile("/repo/baseDir/components/gardener-extensions/networking-calico/extension.yaml")
50+
Expect(err).ToNot(HaveOccurred())
51+
Expect(string(content)).To(ContainSubstring("apiVersion: operator.gardener.cloud/v1alpha1"))
52+
Expect(string(content)).To(ContainSubstring("kind: Extension"))
53+
54+
content, err = fs.ReadFile("/repo/baseDir/components/gardener-extensions/networking-calico/kustomization.yaml")
55+
Expect(err).ToNot(HaveOccurred())
56+
Expect(string(content)).To(ContainSubstring("- extension.yaml"))
57+
})
58+
})
59+
60+
Describe("#GenerateLandscape", func() {
61+
BeforeEach(func() {
62+
generateOpts.TargetDirPath = "/repo/landscapeDir"
63+
generateOpts.Config = &v1alpha1.LandscapeKitConfiguration{
64+
Git: &v1alpha1.GitRepository{Paths: v1alpha1.PathConfiguration{Landscape: "./landscapeDir", Base: "./baseDir"}},
65+
}
66+
})
67+
68+
It("should generate only the flux kustomization into the landscape dir", func() {
69+
component := networking_calico.NewComponent()
70+
landscapeOpts, err := components.NewLandscapeOptions(generateOpts, fs)
71+
Expect(component.GenerateLandscape(landscapeOpts)).To(Succeed())
72+
Expect(err).ToNot(HaveOccurred())
73+
74+
exists, err := fs.DirExists("/repo/baseDir")
75+
Expect(err).ToNot(HaveOccurred())
76+
Expect(exists).To(BeFalse())
77+
78+
content, err := fs.ReadFile("/repo/landscapeDir/components/gardener-extensions/networking-calico/flux-kustomization.yaml")
79+
Expect(err).ToNot(HaveOccurred())
80+
Expect(string(content)).To(ContainSubstring("path: landscapeDir/components/gardener-extensions/networking-calico"))
81+
82+
content, err = fs.ReadFile("/repo/landscapeDir/components/gardener-extensions/networking-calico/kustomization.yaml")
83+
Expect(err).ToNot(HaveOccurred())
84+
Expect(string(content)).To(ContainSubstring("- ../../../../baseDir/components/gardener-extensions/networking-calico"))
85+
})
86+
})
87+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package networking_calico_test
6+
7+
import (
8+
"testing"
9+
10+
. "github.com/onsi/ginkgo/v2"
11+
. "github.com/onsi/gomega"
12+
)
13+
14+
func TestNetworkingCalico(t *testing.T) {
15+
RegisterFailHandler(Fail)
16+
RunSpecs(t, "Components Networking Calico Suite")
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: operator.gardener.cloud/v1alpha1
2+
kind: Extension
3+
metadata:
4+
annotations:
5+
security.gardener.cloud/pod-security-enforce: baseline
6+
name: networking-calico
7+
spec:
8+
deployment:
9+
admission:
10+
runtimeCluster:
11+
helm:
12+
ociRepository:
13+
ref: europe-docker.pkg.dev/gardener-project/public/charts/gardener/extensions/admission-calico-runtime:{{ .version }}
14+
virtualCluster:
15+
helm:
16+
ociRepository:
17+
ref: europe-docker.pkg.dev/gardener-project/public/charts/gardener/extensions/admission-calico-application:{{ .version }}
18+
extension:
19+
helm:
20+
ociRepository:
21+
ref: europe-docker.pkg.dev/gardener-project/public/charts/gardener/extensions/networking-calico:{{ .version }}
22+
resources:
23+
- kind: Network
24+
type: calico
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- extension.yaml
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: operator.gardener.cloud/v1alpha1
2+
kind: Extension
3+
metadata:
4+
name: networking-calico
5+
spec:
6+
deployment:
7+
admission:
8+
values:
9+
extension:
10+
values:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: kustomize.toolkit.fluxcd.io/v1
2+
kind: Kustomization
3+
metadata:
4+
name: extension-networking-calico
5+
namespace: garden
6+
spec:
7+
interval: 30m
8+
path: {{ .landscapeComponentPath }}
9+
prune: true
10+
sourceRef:
11+
kind: GitRepository
12+
name: flux-system
13+
namespace: flux-system
14+
dependsOn:
15+
- name: gardener-operator
16+
namespace: garden
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- {{ .relativePathToBaseComponent }}
5+
patches:
6+
- path: extension.yaml

0 commit comments

Comments
 (0)