diff --git a/README.md b/README.md index b05fa8169..d5cb0a7da 100644 --- a/README.md +++ b/README.md @@ -3,24 +3,54 @@ [![CI Build status](https://concourse.ci.gardener.cloud/api/v1/teams/gardener/pipelines/gardener-extension-os-gardenlinux-master/jobs/master-head-update-job/badge)](https://concourse.ci.gardener.cloud/teams/gardener/pipelines/gardener-extension-os-gardenlinux-master/jobs/master-head-update-job) [![Go Report Card](https://goreportcard.com/badge/github.com/gardener/gardener-extension-os-gardenlinux)](https://goreportcard.com/report/github.com/gardener/gardener-extension-os-gardenlinux) -This controller operates on the [`OperatingSystemConfig`](https://github.com/gardener/gardener/blob/master/docs/proposals/01-extensibility.md#cloud-config-user-data-for-bootstrapping-machines) resource in the `extensions.gardener.cloud/v1alpha1` API group. It manages those objects that are requesting [Garden Linux OS](https://gardenlinux.io/) configuration (`.spec.type=gardenlinux`): +This controller operates on the [`OperatingSystemConfig`](https://github.com/gardener/gardener/blob/master/docs/proposals/01-extensibility.md#cloud-config-user-data-for-bootstrapping-machines) resource in the `extensions.gardener.cloud/v1alpha1` API group. + +It manages those objects that are requesting... + +- [Garden Linux OS](https://gardenlinux.io/) configuration (`.spec.type=gardenlinux`): + + ```yaml + --- + apiVersion: extensions.gardener.cloud/v1alpha1 + kind: OperatingSystemConfig + metadata: + name: pool-01-original + namespace: default + spec: + type: gardenlinux + units: + ... + files: + ... + ``` + + Please find [a concrete example](example/40-operatingsystemconfig-gardenlinux.yaml) in the `example` folder. + + +- MemoryOne on Garden Linux configuration (`spec.type=memoryone-gardenlinux`): + + ```yaml + --- + apiVersion: extensions.gardener.cloud/v1alpha1 + kind: OperatingSystemConfig + metadata: + name: pool-01-original + namespace: default + spec: + type: memoryone-gardenlinux + units: + ... + files: + ... + providerConfig: + apiVersion: memoryone-gardenlinux.os.extensions.gardener.cloud/v1alpha1 + kind: OperatingSystemConfiguration + memoryTopology: "2" + systemMemory: "6x" + ``` + + Please find [a concrete example](example/40-operatingsystemconfig-memoryonegardenlinux.yaml) in the `example` folder. -```yaml ---- -apiVersion: extensions.gardener.cloud/v1alpha1 -kind: OperatingSystemConfig -metadata: - name: pool-01-original - namespace: default -spec: - type: gardenlinux - units: - ... - files: - ... -``` - -Please find [a concrete example](example/40-operatingsystemconfig.yaml) in the `example` folder. After reconciliation the resulting data will be stored in a secret within the same namespace (as the config itself might contain confidential data). The name of the secret will be written into the resource's `.status` field: @@ -43,7 +73,7 @@ The secret has one data key `cloud_config` that stores the generation. An example for a `ControllerRegistration` resource that can be used to register this controller to Gardener can be found [here](example/controller-registration.yaml). -This controller is based on revision [b5ba8164](https://github.com/gardener/gardener-extension-os-ubuntu-alicloud/commit/b5ba8164ed4c52872b1d4bd5ee3eaa4ed58da966) of [gardener-extension-os-ubuntu-alicloud](https://github.com/gardener/gardener-extension-os-ubuntu-alicloud). Its implementation is using the [`oscommon`](https://github.com/gardener/gardener/blob/master/extensions/pkg/controller/operatingsystemconfig/oscommon/README.md) library for operating system configuration controllers. +The implementation of this controller is using Gardeners [`oscommon`](https://github.com/gardener/gardener/blob/master/extensions/pkg/controller/operatingsystemconfig/oscommon/README.md) library for operating system configuration controllers. Please find more information regarding the extensibility concepts and a detailed proposal [here](https://github.com/gardener/gardener/blob/master/docs/proposals/01-extensibility.md). diff --git a/charts/gardener-extension-os-gardenlinux/doc.go b/charts/gardener-extension-os-gardenlinux/doc.go index b031acb78..eb87a47b0 100644 --- a/charts/gardener-extension-os-gardenlinux/doc.go +++ b/charts/gardener-extension-os-gardenlinux/doc.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:generate sh -c "../../vendor/github.com/gardener/gardener/hack/generate-controller-registration.sh os-gardenlinux . $(cat ../../VERSION) ../../example/controller-registration.yaml OperatingSystemConfig:gardenlinux" +//go:generate sh -c "../../vendor/github.com/gardener/gardener/hack/generate-controller-registration.sh os-gardenlinux . $(cat ../../VERSION) ../../example/controller-registration.yaml OperatingSystemConfig:gardenlinux OperatingSystemConfig:memoryone-gardenlinux" // Package chart enables go:generate support for generating the correct controller registration. package chart diff --git a/cmd/gardener-extension-os-gardenlinux/app/app.go b/cmd/gardener-extension-os-gardenlinux/app/app.go index bc81145df..b33f22b06 100644 --- a/cmd/gardener-extension-os-gardenlinux/app/app.go +++ b/cmd/gardener-extension-os-gardenlinux/app/app.go @@ -35,11 +35,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator" + "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator/gardenlinux" + "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator/memoryone" ) var ( ctrlName = "gardenlinux" - osTypes = []string{"gardenlinux"} + osTypes = []string{gardenlinux.OSTypeGardenLinux, memoryone.OSTypeMemoryOneGardenLinux} ) // NewControllerCommand returns a new Command with a new Generator diff --git a/example/40-operatingsystemconfig.yaml b/example/40-operatingsystemconfig-gardenlinux.yaml similarity index 100% rename from example/40-operatingsystemconfig.yaml rename to example/40-operatingsystemconfig-gardenlinux.yaml diff --git a/example/40-operatingsystemconfig-memoryonegardenlinux.yaml b/example/40-operatingsystemconfig-memoryonegardenlinux.yaml new file mode 100644 index 000000000..24b1f992f --- /dev/null +++ b/example/40-operatingsystemconfig-memoryonegardenlinux.yaml @@ -0,0 +1,49 @@ +--- +apiVersion: extensions.gardener.cloud/v1alpha1 +kind: OperatingSystemConfig +metadata: + name: pool-02-original + namespace: default +spec: + type: memoryone-gardenlinux + units: + - name: docker.service + dropIns: + - name: 10-docker-opts.conf + content: | + [Service] + Environment="DOCKER_OPTS=--log-opt max-size=60m --log-opt max-file=3" + - name: docker-monitor.service + command: start + enable: true + content: | + [Unit] + Description=Docker-monitor daemon + After=kubelet.service + [Install] + WantedBy=multi-user.target + [Service] + Restart=always + EnvironmentFile=/etc/environment + ExecStart=/opt/bin/health-monitor docker + files: + - path: /var/lib/example/file.txt + permissions: 0644 + encoding: b64 + content: + secretRef: + name: example-file + dataKey: file.txt + - path: /etc/sysctl.d/99-k8s-general.conf + permissions: 0644 + content: + inline: + data: | + # A higher vm.max_map_count is great for elasticsearch, mongo, or other mmap users + # See https://github.com/kubernetes/kops/issues/1340 + vm.max_map_count = 135217728 + providerConfig: + apiVersion: memoryone-gardenlinux.os.extensions.gardener.cloud/v1alpha1 + kind: OperatingSystemConfiguration + memoryTopology: "3" + systemMemory: "7x" diff --git a/example/controller-registration.yaml b/example/controller-registration.yaml index c2e5c1a70..90d09f6d1 100644 --- a/example/controller-registration.yaml +++ b/example/controller-registration.yaml @@ -5,7 +5,7 @@ metadata: name: os-gardenlinux type: helm providerConfig: - chart: H4sIAAAAAAAAA+0ca2/jNnI/61fMaa/Y3SKSbCdxejoUqOukbXBpEsTpFkVRLGiJttXIokpS9rrbvd9+Q1Iv23FsJ2n20ppYxDJFDocznCfHOyQ8pAnlDn0vaSIiljhMOEPdG0dJ9t578eDWwHZ0eKg/sS1+6ufm/kGzddhqt1V/s73fbL6Aw4cvvb5lQhIO8IIzJu8at+79M23Dtfx3RzQeR8OEcXrPNRSD2wcHK/mPbJ/nf6txcNB+AY1H3emK9jfn/0u4JFJSngiQDAybYTqiCfSzKA6jZAgpCW7IkArXegnXo0iAyNKUcYkPeDRiGMasD2MigxGO3gNOYyKjCcV5clTrJ0mIABI6xLcsgdcpp4PoPQ1hGuG4f7xx4SKJZ8ASPVOhBCnlgIeQupZ73HvXk4gbguiy8RgBvO32IIy4sNxhJD3916Bvuf3fuaf/Fh2joaf+FF/FJPEqQH3cX5bCIIqpsD53xTTFv31yg3/lGJ//i0PfEh6xTMDp8QkumHL2Kw2k5UYhJZ4Zh12WOxEBC6lnfWqubt7Wy393RLh0Z2Qc33eNdfLf2j9clP/W/k7+n6SRNHpLueK7D5OmRdK0/Go33YZthVQEPEql7urAd2gMIFBHAgaMgxxR+DY/QvkDnKljAxc9KI+UlZAx9WHtWbMmxdoNFxd/RmL0bNt6+Q9Z4A7ZQ9ZYI/+tRvtowf87wi87+X+K5nloBtMZWsqRhNfBG0Dd24Be5x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aKFLrwAF2riy9Kvw95XrmNxcdUzR2W0VZB/YbYFnzNXad2vZUmV2nuFOxlgvKOvDzL5ZV0L9j7khy24xbeYmxutT3gvone3kwvAfUHbkgiprawQx0tqSqVrXykQrgy5z2Ze1rMa/kSlGcWzLHROFfNL7Y/Vp/13Zt13Zt13bt2bT/A2xLARkAUAAA values: image: tag: v0.21.0-dev @@ -23,3 +23,5 @@ spec: resources: - kind: OperatingSystemConfig type: gardenlinux + - kind: OperatingSystemConfig + type: memoryone-gardenlinux diff --git a/go.mod b/go.mod index 63259db02..3d6c01b3a 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( k8s.io/client-go v0.26.3 k8s.io/code-generator v0.26.3 k8s.io/component-base v0.26.3 + k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 sigs.k8s.io/controller-runtime v0.14.6 ) @@ -110,7 +111,6 @@ require ( k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect k8s.io/kubelet v0.26.3 // indirect k8s.io/metrics v0.26.3 // indirect - k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20221212190805-d4f1e822ca11 // indirect sigs.k8s.io/controller-tools v0.11.3 // indirect sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect diff --git a/hack/api-reference/memoryonegardenlinux.json b/hack/api-reference/memoryonegardenlinux.json new file mode 100644 index 000000000..c4026a6da --- /dev/null +++ b/hack/api-reference/memoryonegardenlinux.json @@ -0,0 +1,24 @@ +{ + "hideMemberFields": [ + "TypeMeta" + ], + "hideTypePatterns": [ + "ParseError$", + "List$" + ], + "externalPackages": [ + { + "typeMatchPrefix": "^k8s\\.io/(api|apimachinery/pkg/apis)/", + "docsURLTemplate": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}" + }, + { + "typeMatchPrefix": "github.com/gardener/gardener/extensions/pkg/controller/healthcheck/config", + "docsURLTemplate": "https://github.com/gardener/gardener/extensions/pkg/controller/healthcheck/config" + } + ], + "typeDisplayNamePrefixOverrides": { + "k8s.io/api/": "Kubernetes ", + "k8s.io/apimachinery/pkg/apis/": "Kubernetes " + }, + "markdownDisabled": false +} diff --git a/hack/api-reference/memoryonegardenlinux.md b/hack/api-reference/memoryonegardenlinux.md new file mode 100644 index 000000000..35f407cf0 --- /dev/null +++ b/hack/api-reference/memoryonegardenlinux.md @@ -0,0 +1,74 @@ +

Packages:

+ +

memoryone-gardenlinux.os.extensions.gardener.cloud/v1alpha1

+

+

Package v1alpha1 contains the v1alpha1 version of the API.

+

+Resource Types: + +

OperatingSystemConfiguration +

+

+

OperatingSystemConfiguration allows to specify configuration for the operating system.

+

+ + + + + + + + + + + + + + + + + + + + + + + + + +
FieldDescription
+apiVersion
+string
+ +memoryone-gardenlinux.os.extensions.gardener.cloud/v1alpha1 + +
+kind
+string +
OperatingSystemConfiguration
+memoryTopology
+ +string + +
+(Optional) +

MemoryTopology allows to configure the mem_topology parameter. If not present, it will default to 2.

+
+systemMemory
+ +string + +
+(Optional) +

SystemMemory allows to configure the system_memory parameter. If not present, it will default to 6x.

+
+
+

+Generated with gen-crd-api-reference-docs +

diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh new file mode 100755 index 000000000..6b9bda2cf --- /dev/null +++ b/hack/update-codegen.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +# We need to explicitly pass GO111MODULE=off to k8s.io/code-generator as it is significantly slower otherwise, +# see https://github.com/kubernetes/code-generator/issues/100. +export GO111MODULE=off + +rm -f $GOPATH/bin/*-gen + +PROJECT_ROOT=$(dirname $0)/.. + +bash "${PROJECT_ROOT}"/vendor/k8s.io/code-generator/generate-internal-groups.sh \ + deepcopy,defaulter \ + github.com/gardener/gardener-extension-os-gardenlinux/pkg/client \ + github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis \ + github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis \ + "memoryonegardenlinux:v1alpha1" \ + --go-header-file "${PROJECT_ROOT}/vendor/github.com/gardener/gardener/hack/LICENSE_BOILERPLATE.txt" + +bash "${PROJECT_ROOT}"/vendor/k8s.io/code-generator/generate-internal-groups.sh \ + conversion \ + github.com/gardener/gardener-extension-os-gardenlinux/pkg/client \ + github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis \ + github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis \ + "memoryonegardenlinux:v1alpha1" \ + --extra-peer-dirs=github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux,github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux/v1alpha1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/conversion,k8s.io/apimachinery/pkg/runtime \ + --go-header-file "${PROJECT_ROOT}/vendor/github.com/gardener/gardener/hack/LICENSE_BOILERPLATE.txt" diff --git a/pkg/apis/memoryonegardenlinux/doc.go b/pkg/apis/memoryonegardenlinux/doc.go new file mode 100644 index 000000000..6cdf0e9ef --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/doc.go @@ -0,0 +1,20 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +k8s:deepcopy-gen=package +// +groupName="memoryone-gardenlinux.os.extensions.gardener.cloud" + +//go:generate ../../../hack/update-codegen.sh + +package memoryonegardenlinux // import "github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux" diff --git a/pkg/apis/memoryonegardenlinux/install/install.go b/pkg/apis/memoryonegardenlinux/install/install.go new file mode 100644 index 000000000..d7603b051 --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/install/install.go @@ -0,0 +1,43 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package install + +import ( + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + "github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux" + "github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux/v1alpha1" +) + +var ( + schemeBuilder = runtime.NewSchemeBuilder( + v1alpha1.AddToScheme, + memoryonegardenlinux.AddToScheme, + setVersionPriority, + ) + + // AddToScheme adds all APIs to the scheme. + AddToScheme = schemeBuilder.AddToScheme +) + +func setVersionPriority(scheme *runtime.Scheme) error { + return scheme.SetVersionPriority(v1alpha1.SchemeGroupVersion) +} + +// Install installs all APIs in the scheme. +func Install(scheme *runtime.Scheme) { + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/pkg/apis/memoryonegardenlinux/register.go b/pkg/apis/memoryonegardenlinux/register.go new file mode 100644 index 000000000..2b3383e7e --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/register.go @@ -0,0 +1,47 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. +// This file is licensed under the Apache Software License, v. 2 except as noted +// otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package memoryonegardenlinux + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "memoryone-gardenlinux.os.extensions.gardener.cloud" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + localSchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + // AddToScheme is a pointer to SchemeBuilder.AddToScheme. + AddToScheme = localSchemeBuilder.AddToScheme +) + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &OperatingSystemConfiguration{}, + ) + return nil +} diff --git a/pkg/apis/memoryonegardenlinux/types.go b/pkg/apis/memoryonegardenlinux/types.go new file mode 100644 index 000000000..b2cbe32d5 --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/types.go @@ -0,0 +1,31 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package memoryonegardenlinux + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// OperatingSystemConfiguration infrastructure configuration resource +type OperatingSystemConfiguration struct { + metav1.TypeMeta + + // MemoryTopology allows to configure the `mem_topology` parameter. If not present, it will default to `2`. + MemoryTopology *string + // SystemMemory allows to configure the `system_memory` parameter. If not present, it will default to `6x`. + SystemMemory *string +} diff --git a/pkg/apis/memoryonegardenlinux/v1alpha1/defaults.go b/pkg/apis/memoryonegardenlinux/v1alpha1/defaults.go new file mode 100644 index 000000000..40a1e6b4a --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/v1alpha1/defaults.go @@ -0,0 +1,43 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" +) + +func addDefaultingFuncs(scheme *runtime.Scheme) error { + return RegisterDefaults(scheme) +} + +// SetDefaults_OperatingSystemConfiguration sets the defaults for the Garden Linux operating system configuration +func SetDefaults_OperatingSystemConfiguration(obj *OperatingSystemConfiguration) { + if isEmptyString(obj.MemoryTopology) { + obj.MemoryTopology = pointer.String("2") + } + + if isEmptyString(obj.SystemMemory) { + obj.SystemMemory = pointer.String("6x") + } +} + +// isEmptyString returns true if pointer to a string is either nil or the string has zero length +func isEmptyString(s *string) bool { + if s == nil || len(*s) == 0 { + return true + } + return false +} diff --git a/pkg/apis/memoryonegardenlinux/v1alpha1/doc.go b/pkg/apis/memoryonegardenlinux/v1alpha1/doc.go new file mode 100644 index 000000000..9cf880e4a --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/v1alpha1/doc.go @@ -0,0 +1,24 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +k8s:deepcopy-gen=package +// +k8s:conversion-gen=github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux +// +k8s:openapi-gen=true +// +k8s:defaulter-gen=TypeMeta + +//go:generate gen-crd-api-reference-docs -api-dir . -config ../../../../hack/api-reference/memoryonegardenlinux.json -template-dir ../../../../vendor/github.com/gardener/gardener/hack/api-reference/template -out-file ../../../../hack/api-reference/memoryonegardenlinux.md + +// Package v1alpha1 contains the v1alpha1 version of the API. +// +groupName=memoryone-gardenlinux.os.extensions.gardener.cloud +package v1alpha1 // import "github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux/v1alpha1" diff --git a/pkg/apis/memoryonegardenlinux/v1alpha1/register.go b/pkg/apis/memoryonegardenlinux/v1alpha1/register.go new file mode 100644 index 000000000..527888eed --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/v1alpha1/register.go @@ -0,0 +1,45 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "memoryone-gardenlinux.os.extensions.gardener.cloud" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + localSchemeBuilder = runtime.NewSchemeBuilder(addDefaultingFuncs, addKnownTypes) + // AddToScheme is a pointer to SchemeBuilder.AddToScheme. + AddToScheme = localSchemeBuilder.AddToScheme +) + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &OperatingSystemConfiguration{}, + ) + return nil +} diff --git a/pkg/apis/memoryonegardenlinux/v1alpha1/types.go b/pkg/apis/memoryonegardenlinux/v1alpha1/types.go new file mode 100644 index 000000000..302243c01 --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/v1alpha1/types.go @@ -0,0 +1,34 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// OperatingSystemConfiguration allows to specify configuration for the operating system. +type OperatingSystemConfiguration struct { + metav1.TypeMeta `json:",inline"` + + // MemoryTopology allows to configure the `mem_topology` parameter. If not present, it will default to `2`. + // +optional + MemoryTopology *string `json:"memoryTopology,omitempty"` + // SystemMemory allows to configure the `system_memory` parameter. If not present, it will default to `6x`. + // +optional + SystemMemory *string `json:"systemMemory,omitempty"` +} diff --git a/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.conversion.go b/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.conversion.go new file mode 100644 index 000000000..0be5789d0 --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.conversion.go @@ -0,0 +1,72 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by conversion-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + unsafe "unsafe" + + memoryonegardenlinux "github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux" + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + +// RegisterConversions adds conversion functions to the given scheme. +// Public to allow building arbitrary schemes. +func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*OperatingSystemConfiguration)(nil), (*memoryonegardenlinux.OperatingSystemConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_OperatingSystemConfiguration_To_memoryonegardenlinux_OperatingSystemConfiguration(a.(*OperatingSystemConfiguration), b.(*memoryonegardenlinux.OperatingSystemConfiguration), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*memoryonegardenlinux.OperatingSystemConfiguration)(nil), (*OperatingSystemConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_memoryonegardenlinux_OperatingSystemConfiguration_To_v1alpha1_OperatingSystemConfiguration(a.(*memoryonegardenlinux.OperatingSystemConfiguration), b.(*OperatingSystemConfiguration), scope) + }); err != nil { + return err + } + return nil +} + +func autoConvert_v1alpha1_OperatingSystemConfiguration_To_memoryonegardenlinux_OperatingSystemConfiguration(in *OperatingSystemConfiguration, out *memoryonegardenlinux.OperatingSystemConfiguration, s conversion.Scope) error { + out.MemoryTopology = (*string)(unsafe.Pointer(in.MemoryTopology)) + out.SystemMemory = (*string)(unsafe.Pointer(in.SystemMemory)) + return nil +} + +// Convert_v1alpha1_OperatingSystemConfiguration_To_memoryonegardenlinux_OperatingSystemConfiguration is an autogenerated conversion function. +func Convert_v1alpha1_OperatingSystemConfiguration_To_memoryonegardenlinux_OperatingSystemConfiguration(in *OperatingSystemConfiguration, out *memoryonegardenlinux.OperatingSystemConfiguration, s conversion.Scope) error { + return autoConvert_v1alpha1_OperatingSystemConfiguration_To_memoryonegardenlinux_OperatingSystemConfiguration(in, out, s) +} + +func autoConvert_memoryonegardenlinux_OperatingSystemConfiguration_To_v1alpha1_OperatingSystemConfiguration(in *memoryonegardenlinux.OperatingSystemConfiguration, out *OperatingSystemConfiguration, s conversion.Scope) error { + out.MemoryTopology = (*string)(unsafe.Pointer(in.MemoryTopology)) + out.SystemMemory = (*string)(unsafe.Pointer(in.SystemMemory)) + return nil +} + +// Convert_memoryonegardenlinux_OperatingSystemConfiguration_To_v1alpha1_OperatingSystemConfiguration is an autogenerated conversion function. +func Convert_memoryonegardenlinux_OperatingSystemConfiguration_To_v1alpha1_OperatingSystemConfiguration(in *memoryonegardenlinux.OperatingSystemConfiguration, out *OperatingSystemConfiguration, s conversion.Scope) error { + return autoConvert_memoryonegardenlinux_OperatingSystemConfiguration_To_v1alpha1_OperatingSystemConfiguration(in, out, s) +} diff --git a/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 000000000..3b76dad76 --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,61 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OperatingSystemConfiguration) DeepCopyInto(out *OperatingSystemConfiguration) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.MemoryTopology != nil { + in, out := &in.MemoryTopology, &out.MemoryTopology + *out = new(string) + **out = **in + } + if in.SystemMemory != nil { + in, out := &in.SystemMemory, &out.SystemMemory + *out = new(string) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OperatingSystemConfiguration. +func (in *OperatingSystemConfiguration) DeepCopy() *OperatingSystemConfiguration { + if in == nil { + return nil + } + out := new(OperatingSystemConfiguration) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *OperatingSystemConfiguration) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.defaults.go b/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.defaults.go new file mode 100644 index 000000000..ce078561a --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/v1alpha1/zz_generated.defaults.go @@ -0,0 +1,40 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by defaulter-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + scheme.AddTypeDefaultingFunc(&OperatingSystemConfiguration{}, func(obj interface{}) { + SetObjectDefaults_OperatingSystemConfiguration(obj.(*OperatingSystemConfiguration)) + }) + return nil +} + +func SetObjectDefaults_OperatingSystemConfiguration(in *OperatingSystemConfiguration) { + SetDefaults_OperatingSystemConfiguration(in) +} diff --git a/pkg/apis/memoryonegardenlinux/zz_generated.deepcopy.go b/pkg/apis/memoryonegardenlinux/zz_generated.deepcopy.go new file mode 100644 index 000000000..8550664a2 --- /dev/null +++ b/pkg/apis/memoryonegardenlinux/zz_generated.deepcopy.go @@ -0,0 +1,61 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package memoryonegardenlinux + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OperatingSystemConfiguration) DeepCopyInto(out *OperatingSystemConfiguration) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.MemoryTopology != nil { + in, out := &in.MemoryTopology, &out.MemoryTopology + *out = new(string) + **out = **in + } + if in.SystemMemory != nil { + in, out := &in.SystemMemory, &out.SystemMemory + *out = new(string) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OperatingSystemConfiguration. +func (in *OperatingSystemConfiguration) DeepCopy() *OperatingSystemConfiguration { + if in == nil { + return nil + } + out := new(OperatingSystemConfiguration) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *OperatingSystemConfiguration) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/pkg/generator/generator.go b/pkg/generator/generator.go index cff986065..00c29de96 100644 --- a/pkg/generator/generator.go +++ b/pkg/generator/generator.go @@ -25,6 +25,7 @@ import ( runtimeutils "k8s.io/apimachinery/pkg/util/runtime" "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator/gardenlinux" + "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator/memoryone" ) var ( @@ -51,20 +52,33 @@ func init() { cloudInitGenerator = &GardenLinuxCloudInitGenerator{ cloudInitGenerator: ostemplate.NewCloudInitGenerator(cloudInitTemplate, ostemplate.DefaultUnitsPath, cmd, additionalValues), } + } // additionalValues provides additional values to the cloud-init template -func additionalValues(*extensionsv1alpha1.OperatingSystemConfig) (map[string]interface{}, error) { - return map[string]interface{}{ +func additionalValues(osc *extensionsv1alpha1.OperatingSystemConfig) (map[string]interface{}, error) { + values := map[string]interface{}{ "unitsToEnable": unitsToEnable, - }, nil + } + + if err := memoryone.MemoryOneValues(osc, values); err != nil { + return nil, err + } + + return values, nil +} + +// isSupportedOscType checks if the OperatingSystemConfig's type is one of those for which this extension is responsbile +func isSupportedOscType(osc *generator.OperatingSystemConfig) bool { + return osc.Object.Spec.Type == gardenlinux.OSTypeGardenLinux || + osc.Object.Spec.Type == memoryone.OSTypeMemoryOneGardenLinux } // Generate generates a Garden Linux specific cloud-init script from the given OperatingSystemConfig. func (g *GardenLinuxCloudInitGenerator) Generate(logger logr.Logger, osc *generator.OperatingSystemConfig) ([]byte, *string, error) { // we are only setting this up if the worker pool is configured with containerd - if osc.Object.Spec.Type == gardenlinux.OSTypeGardenLinux && + if isSupportedOscType(osc) && osc.Object.Spec.Purpose == extensionsv1alpha1.OperatingSystemConfigPurposeReconcile && osc.CRI != nil && osc.CRI.Name == extensionsv1alpha1.CRINameContainerD { diff --git a/pkg/generator/generator_suite_test.go b/pkg/generator/generator_suite_test.go index c3747b69d..080dd30a2 100644 --- a/pkg/generator/generator_suite_test.go +++ b/pkg/generator/generator_suite_test.go @@ -15,13 +15,20 @@ package generator_test import ( + "encoding/json" "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/runtime" ) func TestInternal(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Generator Suite") } + +func encode(obj runtime.Object) []byte { + data, _ := json.Marshal(obj) + return data +} diff --git a/pkg/generator/generator_test.go b/pkg/generator/generator_test.go index de67d1d83..e278088e7 100644 --- a/pkg/generator/generator_test.go +++ b/pkg/generator/generator_test.go @@ -21,9 +21,13 @@ import ( "github.com/go-logr/logr" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/utils/pointer" + "github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux/v1alpha1" gardenlinux_generator "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator" "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator/gardenlinux" + "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator/memoryone" "github.com/gardener/gardener-extension-os-gardenlinux/pkg/generator/testfiles" ) @@ -61,7 +65,40 @@ dataKey: token`) Name: extensionsv1alpha1.CRINameContainerD, } - osctemplate = commongen.OperatingSystemConfig{ + units = []*commongen.Unit{ + { + Name: unit1, + Content: unitContent, + }, + { + Name: unit2, + Content: unitContent, + DropIns: []*commongen.DropIn{ + { + Name: dropin, + Content: dropinContent, + }, + }, + }, + { + Name: ccdService, + }, + } + + files = []*commongen.File{ + { + Path: filePath, + Content: fileContent, + Permissions: &permissions, + }, + } + + memoryOneOsConfig = &v1alpha1.OperatingSystemConfiguration{ + MemoryTopology: pointer.String("3"), + SystemMemory: pointer.String("7x"), + } + + gardenlinuxOsctemplate = commongen.OperatingSystemConfig{ Object: &extensionsv1alpha1.OperatingSystemConfig{ Spec: extensionsv1alpha1.OperatingSystemConfigSpec{ Purpose: extensionsv1alpha1.OperatingSystemConfigPurposeProvision, @@ -70,32 +107,24 @@ dataKey: token`) }, }, }, - Units: []*commongen.Unit{ - { - Name: unit1, - Content: unitContent, - }, - { - Name: unit2, - Content: unitContent, - DropIns: []*commongen.DropIn{ - { - Name: dropin, - Content: dropinContent, + Units: units, + Files: files, + } + + memoryOneOscTemplate = commongen.OperatingSystemConfig{ + Object: &extensionsv1alpha1.OperatingSystemConfig{ + Spec: extensionsv1alpha1.OperatingSystemConfigSpec{ + Purpose: extensionsv1alpha1.OperatingSystemConfigPurposeProvision, + DefaultSpec: extensionsv1alpha1.DefaultSpec{ + Type: memoryone.OSTypeMemoryOneGardenLinux, + ProviderConfig: &runtime.RawExtension{ + Raw: encode(memoryOneOsConfig), }, }, }, - { - Name: ccdService, - }, - }, - Files: []*commongen.File{ - { - Path: filePath, - Content: fileContent, - Permissions: &permissions, - }, }, + Units: units, + Files: files, } osc commongen.OperatingSystemConfig @@ -103,75 +132,174 @@ dataKey: token`) var _ = Describe("Garden Linux OS Generator Test", func() { - Describe("Conformance Tests Bootstrap", func() { - g := gardenlinux_generator.CloudInitGenerator() - test.DescribeTest(gardenlinux_generator.CloudInitGenerator(), testfiles.Files)() + Context("Garden Linux", func() { - BeforeEach(func() { - osc = osctemplate - osc.Bootstrap = true - osc.Object.Spec.Purpose = extensionsv1alpha1.OperatingSystemConfigPurposeProvision - }) + Describe("Conformance Tests Bootstrap", func() { + g := gardenlinux_generator.CloudInitGenerator() + test.DescribeTest(gardenlinux_generator.CloudInitGenerator(), testfiles.Files)() - It("[docker] [bootstrap] should render correctly", func() { - e, err := testfiles.Files.ReadFile("docker-bootstrap") - expectedCloudInit := byteSlice(e) - Expect(err).NotTo(HaveOccurred()) + BeforeEach(func() { + osc = gardenlinuxOsctemplate + osc.Bootstrap = true + osc.Object.Spec.Purpose = extensionsv1alpha1.OperatingSystemConfigPurposeProvision + }) - osc.CRI = nil - c, _, err := g.Generate(logger, &osc) - cloudInit := byteSlice(c) + It("[docker] [bootstrap] should render correctly", func() { + e, err := testfiles.Files.ReadFile("docker-bootstrap") + expectedCloudInit := byteSlice(e) + Expect(err).NotTo(HaveOccurred()) - Expect(err).NotTo(HaveOccurred()) - Expect(cloudInit).To(Equal(expectedCloudInit)) + osc.CRI = nil + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) + + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) + + It("[containerd] [bootstrap] should render correctly", func() { + e, err := testfiles.Files.ReadFile("containerd-bootstrap") + expectedCloudInit := byteSlice(e) + Expect(err).NotTo(HaveOccurred()) + + osc.CRI = &criConfigContainerd + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) + + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) }) - It("[containerd] [bootstrap] should render correctly", func() { - e, err := testfiles.Files.ReadFile("containerd-bootstrap") - expectedCloudInit := byteSlice(e) - Expect(err).NotTo(HaveOccurred()) + Describe("Conformance Tests Reconcile", func() { + var g = gardenlinux_generator.CloudInitGenerator() + + BeforeEach(func() { + osc = gardenlinuxOsctemplate + osc.Bootstrap = false + osc.Object.Spec.Purpose = extensionsv1alpha1.OperatingSystemConfigPurposeReconcile + }) + + It("[docker] [reconcile] should render correctly", func() { + e, err := testfiles.Files.ReadFile("docker-reconcile") + Expect(err).NotTo(HaveOccurred()) + expectedCloudInit := byteSlice(e) - osc.CRI = &criConfigContainerd - c, _, err := g.Generate(logger, &osc) - cloudInit := byteSlice(c) + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) - Expect(err).NotTo(HaveOccurred()) - Expect(cloudInit).To(Equal(expectedCloudInit)) + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) + + It("[containerd] [reconcile] should render correctly", func() { + e, err := testfiles.Files.ReadFile("containerd-reconcile") + Expect(err).NotTo(HaveOccurred()) + expectedCloudInit := byteSlice(e) + + osc.CRI = &criConfigContainerd + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) + + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) }) }) - Describe("Conformance Tests Reconcile", func() { - var g = gardenlinux_generator.CloudInitGenerator() + Context("MemoryOne on Garden Linux", func() { BeforeEach(func() { - osc = osctemplate - osc.Bootstrap = false - osc.Object.Spec.Purpose = extensionsv1alpha1.OperatingSystemConfigPurposeReconcile + osc = memoryOneOscTemplate }) - It("[docker] [reconcile] should render correctly", func() { - e, err := testfiles.Files.ReadFile("docker-reconcile") - Expect(err).NotTo(HaveOccurred()) - expectedCloudInit := byteSlice(e) + Describe("Conformance Tests Bootstrap", func() { + g := gardenlinux_generator.CloudInitGenerator() + test.DescribeTest(gardenlinux_generator.CloudInitGenerator(), testfiles.Files)() + + BeforeEach(func() { + osc.Bootstrap = true + osc.Object.Spec.Purpose = extensionsv1alpha1.OperatingSystemConfigPurposeProvision + }) + + It("should render correctly for docker", func() { + e, err := testfiles.Files.ReadFile("memoryone-docker-bootstrap") + expectedCloudInit := byteSlice(e) + Expect(err).NotTo(HaveOccurred()) + + osc.CRI = nil + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) - c, _, err := g.Generate(logger, &osc) - cloudInit := byteSlice(c) + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) - Expect(err).NotTo(HaveOccurred()) - Expect(cloudInit).To(Equal(expectedCloudInit)) + It("should render correctly for containerd", func() { + e, err := testfiles.Files.ReadFile("memoryone-containerd-bootstrap") + expectedCloudInit := byteSlice(e) + Expect(err).NotTo(HaveOccurred()) + + osc.CRI = &criConfigContainerd + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) + + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) + + It("should render correctly with default values", func() { + e, err := testfiles.Files.ReadFile("memoryone-containerd-bootstrap-defaults") + expectedCloudInit := byteSlice(e) + Expect(err).NotTo(HaveOccurred()) + + emptyMemoryOneOsConfig := &v1alpha1.OperatingSystemConfiguration{} + + osc.Object.Spec.ProviderConfig = &runtime.RawExtension{ + Raw: encode(emptyMemoryOneOsConfig), + } + + osc.CRI = &criConfigContainerd + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) + + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) }) - It("[containerd] [reconcile] should render correctly", func() { - e, err := testfiles.Files.ReadFile("containerd-reconcile") - Expect(err).NotTo(HaveOccurred()) - expectedCloudInit := byteSlice(e) + Describe("Conformance Tests Reconcile", func() { + var g = gardenlinux_generator.CloudInitGenerator() + + BeforeEach(func() { + osc.Bootstrap = false + osc.Object.Spec.Purpose = extensionsv1alpha1.OperatingSystemConfigPurposeReconcile + }) + + It("must not render memoryone contents during reconcile for docker", func() { + e, err := testfiles.Files.ReadFile("docker-reconcile") + Expect(err).NotTo(HaveOccurred()) + expectedCloudInit := byteSlice(e) + + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) + + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) + + It("must not render memoryone contents during reconcile for containerd", func() { + e, err := testfiles.Files.ReadFile("containerd-reconcile") + Expect(err).NotTo(HaveOccurred()) + expectedCloudInit := byteSlice(e) - osc.CRI = &criConfigContainerd - c, _, err := g.Generate(logger, &osc) - cloudInit := byteSlice(c) + osc.CRI = &criConfigContainerd + c, _, err := g.Generate(logger, &osc) + cloudInit := byteSlice(c) - Expect(err).NotTo(HaveOccurred()) - Expect(cloudInit).To(Equal(expectedCloudInit)) + Expect(err).NotTo(HaveOccurred()) + Expect(cloudInit).To(Equal(expectedCloudInit)) + }) }) }) }) diff --git a/pkg/generator/memoryone/contants.go b/pkg/generator/memoryone/contants.go new file mode 100644 index 000000000..e73ef9432 --- /dev/null +++ b/pkg/generator/memoryone/contants.go @@ -0,0 +1,20 @@ +// Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package memoryone + +const ( + // OSTypMemoryOneGardenLinux is a constant for the Garden Linux extension OS type. + OSTypeMemoryOneGardenLinux = "memoryone-gardenlinux" +) diff --git a/pkg/generator/memoryone/values.go b/pkg/generator/memoryone/values.go new file mode 100644 index 000000000..c6b166b30 --- /dev/null +++ b/pkg/generator/memoryone/values.go @@ -0,0 +1,57 @@ +// Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package memoryone + +import ( + "fmt" + + extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" + runtimeutils "k8s.io/apimachinery/pkg/util/runtime" + + memoryonegardenlinux "github.com/gardener/gardener-extension-os-gardenlinux/pkg/apis/memoryonegardenlinux/v1alpha1" +) + +var decoder runtime.Decoder + +func init() { + scheme := runtime.NewScheme() + runtimeutils.Must(memoryonegardenlinux.AddToScheme(scheme)) + decoder = serializer.NewCodecFactory(scheme).UniversalDecoder() +} + +func MemoryOneValues(osc *extensionsv1alpha1.OperatingSystemConfig, values map[string]interface{}) error { + if osc.Spec.Type == OSTypeMemoryOneGardenLinux { + if osc.Spec.ProviderConfig == nil { + return nil + } + + obj := &memoryonegardenlinux.OperatingSystemConfiguration{} + if _, _, err := decoder.Decode(osc.Spec.ProviderConfig.Raw, nil, obj); err != nil { + return fmt.Errorf("failed to decode provider config: %+v", err) + } + + if obj.MemoryTopology != nil { + values["MemoryOneMemoryTopology"] = *obj.MemoryTopology + } + + if obj.SystemMemory != nil { + values["MemoryOneSystemMemory"] = *obj.SystemMemory + } + } + + return nil +} diff --git a/pkg/generator/templates/cloud-init.gardenlinux.template b/pkg/generator/templates/cloud-init.gardenlinux.template index 80c9f9d61..75affb9ab 100644 --- a/pkg/generator/templates/cloud-init.gardenlinux.template +++ b/pkg/generator/templates/cloud-init.gardenlinux.template @@ -1,5 +1,20 @@ +{{- if and (eq .Type "memoryone-gardenlinux") .Bootstrap -}} +Content-Type: multipart/mixed; boundary="==BOUNDARY==" +MIME-Version: 1.0 +--==BOUNDARY== +Content-Type: text/x-vsmp; section=vsmp +{{- if .AdditionalValues.MemoryOneSystemMemory }} +system_memory={{ .AdditionalValues.MemoryOneSystemMemory }} +{{- end }} +{{- if .AdditionalValues.MemoryOneMemoryTopology }} +mem_topology={{ .AdditionalValues.MemoryOneMemoryTopology }} +{{- end }} +--==BOUNDARY== +Content-Type: text/x-shellscript #!/bin/bash - +{{- else -}} +#!/bin/bash +{{- end -}} {{- define "put-content" -}} cat << EOF | base64 -d > '{{ .Path }}' {{ .Content }} @@ -65,3 +80,7 @@ systemctl enable containerd && systemctl restart containerd systemctl enable docker && systemctl restart docker systemctl enable cloud-config-downloader && systemctl restart cloud-config-downloader {{- end }} +{{- if and (eq .Type "memoryone-gardenlinux") .Bootstrap }} + +--==BOUNDARY== +{{- end }} diff --git a/pkg/generator/testfiles/embed.go b/pkg/generator/testfiles/embed.go index 900e7a68f..a8763b27a 100644 --- a/pkg/generator/testfiles/embed.go +++ b/pkg/generator/testfiles/embed.go @@ -18,5 +18,5 @@ import "embed" // Files contains the contents of the testfiles directory // -//go:embed cloud-* containerd-* docker-* +//go:embed cloud-* containerd-* docker-* memoryone-* var Files embed.FS diff --git a/pkg/generator/testfiles/memoryone-containerd-bootstrap b/pkg/generator/testfiles/memoryone-containerd-bootstrap new file mode 100644 index 000000000..1a30e6d6e --- /dev/null +++ b/pkg/generator/testfiles/memoryone-containerd-bootstrap @@ -0,0 +1,54 @@ +Content-Type: multipart/mixed; boundary="==BOUNDARY==" +MIME-Version: 1.0 +--==BOUNDARY== +Content-Type: text/x-vsmp; section=vsmp +system_memory=7x +mem_topology=3 +--==BOUNDARY== +Content-Type: text/x-shellscript +#!/bin/bash +if [ ! -s /etc/containerd/config.toml ]; then + mkdir -p /etc/containerd/ + containerd config default > /etc/containerd/config.toml + chmod 0644 /etc/containerd/config.toml +fi + +mkdir -p /etc/systemd/system/containerd.service.d +cat < /etc/systemd/system/containerd.service.d/11-exec_config.conf +[Service] +ExecStart= +ExecStart=/usr/bin/containerd --config=/etc/containerd/config.toml +EOF +chmod 0644 /etc/systemd/system/containerd.service.d/11-exec_config.conf + +mkdir -p '/var/lib/kubelet' +cat << EOF | base64 -d > '/var/lib/kubelet/ca.crt' +c2VjcmV0UmVmOgpuYW1lOiBkZWZhdWx0LXRva2VuLWQ5bnpsCmRhdGFLZXk6IHRva2Vu +EOF +chmod '0644' '/var/lib/kubelet/ca.crt' + + + +cat << EOF | base64 -d > '/etc/systemd/system/unit1' +W1VuaXRdCkRlc2NyaXB0aW9uPXRlc3QgY29udGVudApbSW5zdGFsbF0KV2FudGVkQnk9bXVsdGktdXNlci50YXJnZXQKW1NlcnZpY2VdClJlc3RhcnQ9YWx3YXlz +EOF +cat << EOF | base64 -d > '/etc/systemd/system/unit2' +W1VuaXRdCkRlc2NyaXB0aW9uPXRlc3QgY29udGVudApbSW5zdGFsbF0KV2FudGVkQnk9bXVsdGktdXNlci50YXJnZXQKW1NlcnZpY2VdClJlc3RhcnQ9YWx3YXlz +EOF + +mkdir -p '/etc/systemd/system/unit2.d' +cat << EOF | base64 -d > '/etc/systemd/system/unit2.d/dropin' +W1NlcnZpY2VdCkVudmlyb25tZW50PSJET0NLRVJfT1BUUz0tLWxvZy1vcHQgbWF4LXNpemU9NjBtIC0tbG9nLW9wdCBtYXgtZmlsZT0zIg== +EOF + + +grep -sq "^nfsd$" /etc/modules || echo "nfsd" >>/etc/modules +modprobe nfsd +nslookup $(hostname) || systemctl restart systemd-networkd + +systemctl daemon-reload +systemctl enable containerd && systemctl restart containerd +systemctl enable docker && systemctl restart docker +systemctl enable cloud-config-downloader && systemctl restart cloud-config-downloader + +--==BOUNDARY== diff --git a/pkg/generator/testfiles/memoryone-containerd-bootstrap-defaults b/pkg/generator/testfiles/memoryone-containerd-bootstrap-defaults new file mode 100644 index 000000000..fd0ef9e2a --- /dev/null +++ b/pkg/generator/testfiles/memoryone-containerd-bootstrap-defaults @@ -0,0 +1,54 @@ +Content-Type: multipart/mixed; boundary="==BOUNDARY==" +MIME-Version: 1.0 +--==BOUNDARY== +Content-Type: text/x-vsmp; section=vsmp +system_memory=6x +mem_topology=2 +--==BOUNDARY== +Content-Type: text/x-shellscript +#!/bin/bash +if [ ! -s /etc/containerd/config.toml ]; then + mkdir -p /etc/containerd/ + containerd config default > /etc/containerd/config.toml + chmod 0644 /etc/containerd/config.toml +fi + +mkdir -p /etc/systemd/system/containerd.service.d +cat < /etc/systemd/system/containerd.service.d/11-exec_config.conf +[Service] +ExecStart= +ExecStart=/usr/bin/containerd --config=/etc/containerd/config.toml +EOF +chmod 0644 /etc/systemd/system/containerd.service.d/11-exec_config.conf + +mkdir -p '/var/lib/kubelet' +cat << EOF | base64 -d > '/var/lib/kubelet/ca.crt' +c2VjcmV0UmVmOgpuYW1lOiBkZWZhdWx0LXRva2VuLWQ5bnpsCmRhdGFLZXk6IHRva2Vu +EOF +chmod '0644' '/var/lib/kubelet/ca.crt' + + + +cat << EOF | base64 -d > '/etc/systemd/system/unit1' +W1VuaXRdCkRlc2NyaXB0aW9uPXRlc3QgY29udGVudApbSW5zdGFsbF0KV2FudGVkQnk9bXVsdGktdXNlci50YXJnZXQKW1NlcnZpY2VdClJlc3RhcnQ9YWx3YXlz +EOF +cat << EOF | base64 -d > '/etc/systemd/system/unit2' +W1VuaXRdCkRlc2NyaXB0aW9uPXRlc3QgY29udGVudApbSW5zdGFsbF0KV2FudGVkQnk9bXVsdGktdXNlci50YXJnZXQKW1NlcnZpY2VdClJlc3RhcnQ9YWx3YXlz +EOF + +mkdir -p '/etc/systemd/system/unit2.d' +cat << EOF | base64 -d > '/etc/systemd/system/unit2.d/dropin' +W1NlcnZpY2VdCkVudmlyb25tZW50PSJET0NLRVJfT1BUUz0tLWxvZy1vcHQgbWF4LXNpemU9NjBtIC0tbG9nLW9wdCBtYXgtZmlsZT0zIg== +EOF + + +grep -sq "^nfsd$" /etc/modules || echo "nfsd" >>/etc/modules +modprobe nfsd +nslookup $(hostname) || systemctl restart systemd-networkd + +systemctl daemon-reload +systemctl enable containerd && systemctl restart containerd +systemctl enable docker && systemctl restart docker +systemctl enable cloud-config-downloader && systemctl restart cloud-config-downloader + +--==BOUNDARY== diff --git a/pkg/generator/testfiles/memoryone-docker-bootstrap b/pkg/generator/testfiles/memoryone-docker-bootstrap new file mode 100644 index 000000000..f089330e2 --- /dev/null +++ b/pkg/generator/testfiles/memoryone-docker-bootstrap @@ -0,0 +1,40 @@ +Content-Type: multipart/mixed; boundary="==BOUNDARY==" +MIME-Version: 1.0 +--==BOUNDARY== +Content-Type: text/x-vsmp; section=vsmp +system_memory=7x +mem_topology=3 +--==BOUNDARY== +Content-Type: text/x-shellscript +#!/bin/bash + +mkdir -p '/var/lib/kubelet' +cat << EOF | base64 -d > '/var/lib/kubelet/ca.crt' +c2VjcmV0UmVmOgpuYW1lOiBkZWZhdWx0LXRva2VuLWQ5bnpsCmRhdGFLZXk6IHRva2Vu +EOF +chmod '0644' '/var/lib/kubelet/ca.crt' + + + +cat << EOF | base64 -d > '/etc/systemd/system/unit1' +W1VuaXRdCkRlc2NyaXB0aW9uPXRlc3QgY29udGVudApbSW5zdGFsbF0KV2FudGVkQnk9bXVsdGktdXNlci50YXJnZXQKW1NlcnZpY2VdClJlc3RhcnQ9YWx3YXlz +EOF +cat << EOF | base64 -d > '/etc/systemd/system/unit2' +W1VuaXRdCkRlc2NyaXB0aW9uPXRlc3QgY29udGVudApbSW5zdGFsbF0KV2FudGVkQnk9bXVsdGktdXNlci50YXJnZXQKW1NlcnZpY2VdClJlc3RhcnQ9YWx3YXlz +EOF + +mkdir -p '/etc/systemd/system/unit2.d' +cat << EOF | base64 -d > '/etc/systemd/system/unit2.d/dropin' +W1NlcnZpY2VdCkVudmlyb25tZW50PSJET0NLRVJfT1BUUz0tLWxvZy1vcHQgbWF4LXNpemU9NjBtIC0tbG9nLW9wdCBtYXgtZmlsZT0zIg== +EOF + + +grep -sq "^nfsd$" /etc/modules || echo "nfsd" >>/etc/modules +modprobe nfsd +nslookup $(hostname) || systemctl restart systemd-networkd + +systemctl daemon-reload +systemctl enable docker && systemctl restart docker +systemctl enable cloud-config-downloader && systemctl restart cloud-config-downloader + +--==BOUNDARY==