diff --git a/charts/clabernetes/templates/configmap.yaml b/charts/clabernetes/templates/configmap.yaml index 79f4084..fecc9d3 100644 --- a/charts/clabernetes/templates/configmap.yaml +++ b/charts/clabernetes/templates/configmap.yaml @@ -36,10 +36,17 @@ data: {{ .Values.globalConfig.deployment.resourcesByContainerlabKind | toYaml | indent 4 }} privilegedLauncher: "{{ .Values.globalConfig.deployment.privilegedLauncher }}" containerlabDebug: "{{ .Values.globalConfig.deployment.containerlabDebug }}" + {{- if .Values.globalConfig.deployment.containerlabTimeout }} containerlabTimeout: {{ .Values.globalConfig.deployment.containerlabTimeout }} + {{- end }} + {{- if .Values.globalConfig.deployment.containerlabVersion }} + containerlabVersion: {{ .Values.globalConfig.deployment.containerlabVersion }} + {{- end }} inClusterDNSSuffix: {{ .Values.globalConfig.inClusterDNSSuffix }} imagePullThroughMode: {{ .Values.globalConfig.imagePull.imagePullThroughMode }} + {{- if .Values.globalConfig.deployment.launcherImage }} launcherImage: {{ .Values.globalConfig.deployment.launcherImage }} + {{- end }} launcherImagePullPolicy: {{ .Values.globalConfig.deployment.launcherImagePullPolicy }} launcherLogLevel: {{ .Values.globalConfig.deployment.launcherLogLevel }} {{- if .Values.globalConfig.imagePull.criSockOverride }} @@ -49,5 +56,4 @@ data: criKindOverride: {{ .Values.globalConfig.imagePull.criKindOverride }} {{- end }} naming: {{ .Values.globalConfig.naming }} - containerlabVersion: {{ .Values.globalConfig.deployment.containerlabVersion }} {{- end }} \ No newline at end of file diff --git a/charts/clabernetes/templates/deployment.yaml b/charts/clabernetes/templates/deployment.yaml index 643a06f..ddb1f1c 100644 --- a/charts/clabernetes/templates/deployment.yaml +++ b/charts/clabernetes/templates/deployment.yaml @@ -103,7 +103,7 @@ spec: cpu: {{ .Values.manager.resources.requests.cpu }} {{- if .Values.manager.resources.limits }} limits: - {{ toYaml .Values.manager.resources.limits | indent 14 }} + {{ toYaml .Values.manager.resources.limits | indent 12 }} {{- end }} containers: - name: manager @@ -124,7 +124,7 @@ spec: cpu: {{ .Values.manager.resources.requests.cpu }} {{- if .Values.manager.resources.limits }} limits: - {{ toYaml .Values.manager.resources.limits | indent 14 }} + {{ toYaml .Values.manager.resources.limits | indent 12 }} {{- end }} ports: - name: http diff --git a/charts/clabernetes/tests/clicker_enabled/test-fixtures/golden/configmap.yaml b/charts/clabernetes/tests/clicker_enabled/test-fixtures/golden/configmap.yaml index 432a60d..7ea7523 100755 --- a/charts/clabernetes/tests/clicker_enabled/test-fixtures/golden/configmap.yaml +++ b/charts/clabernetes/tests/clicker_enabled/test-fixtures/golden/configmap.yaml @@ -40,8 +40,6 @@ data: containerlabDebug: "false" inClusterDNSSuffix: svc.cluster.local imagePullThroughMode: auto - launcherImage: launcherImagePullPolicy: IfNotPresent launcherLogLevel: info naming: prefixed - containerlabVersion: diff --git a/charts/clabernetes/tests/customized_values/customized_values_test.go b/charts/clabernetes/tests/customized_values/customized_values_test.go new file mode 100644 index 0000000..1432c9d --- /dev/null +++ b/charts/clabernetes/tests/customized_values/customized_values_test.go @@ -0,0 +1,40 @@ +package default_values_test + +import ( + "fmt" + "os" + "path/filepath" + "testing" + + clabernetesconstants "github.com/srl-labs/clabernetes/constants" + clabernetestesthelper "github.com/srl-labs/clabernetes/testhelper" +) + +func TestMain(m *testing.M) { + clabernetestesthelper.Flags() + + os.Exit(m.Run()) +} + +// TestCustomValues -- similar to the default one but we can just chuck in some custom values stuff +// in here to test lots of the helm rendering at once. +func TestCustomValues(t *testing.T) { + t.Parallel() + + testName := "customized_values" + chartName := "clabernetes" + + chartsDir, err := filepath.Abs("../../..") + if err != nil { + t.Error(err) + } + + clabernetestesthelper.HelmTest( + t, + chartName, + testName, + clabernetesconstants.Clabernetes, + fmt.Sprintf("%s-values.yaml", testName), + chartsDir, + ) +} diff --git a/charts/clabernetes/tests/customized_values/test-fixtures/customized_values-values.yaml b/charts/clabernetes/tests/customized_values/test-fixtures/customized_values-values.yaml new file mode 100644 index 0000000..03c86c2 --- /dev/null +++ b/charts/clabernetes/tests/customized_values/test-fixtures/customized_values-values.yaml @@ -0,0 +1,6 @@ +--- +manager: + resources: + limits: + memory: 256Mi + cpu: 100m diff --git a/charts/clabernetes/tests/customized_values/test-fixtures/golden/certificate-secret.yaml b/charts/clabernetes/tests/customized_values/test-fixtures/golden/certificate-secret.yaml new file mode 100755 index 0000000..758e9a0 --- /dev/null +++ b/charts/clabernetes/tests/customized_values/test-fixtures/golden/certificate-secret.yaml @@ -0,0 +1,16 @@ +--- +# Source: clabernetes/templates/certificate-secret.yaml +apiVersion: v1 +kind: Secret +metadata: + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-certificate" + clabernetes/component: certificate + clabernetes/part-of: manager + name: "clabernetes-certificate" +data: {} diff --git a/charts/clabernetes/tests/customized_values/test-fixtures/golden/clusterrole.yaml b/charts/clabernetes/tests/customized_values/test-fixtures/golden/clusterrole.yaml new file mode 100755 index 0000000..98e0854 --- /dev/null +++ b/charts/clabernetes/tests/customized_values/test-fixtures/golden/clusterrole.yaml @@ -0,0 +1,117 @@ +--- +# Source: clabernetes/templates/clusterrole.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-cluster-role" + clabernetes/component: cluster-role + name: "clabernetes-cluster-role" +rules: + - apiGroups: + - clabernetes.containerlab.dev + resources: + - "*" + verbs: + - "*" + - apiGroups: + - apiextensions.k8s.io + resources: + - "*" + verbs: + - "*" + - apiGroups: + - "" + resources: + - nodes + verbs: + - get + - list + - apiGroups: + - "" + resources: + - namespaces + - secrets + - configmaps + - services + - pods + - persistentvolumeclaims + - serviceaccounts + verbs: + - get + - list + - create + - update + - delete + - patch + - watch + - apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - create + - update + - delete + - patch + - watch + - apiGroups: + - apps + resources: + - deployments + verbs: + - get + - list + - create + - update + - delete + - patch + - watch + - apiGroups: + - rbac.authorization.k8s.io + resources: + - rolebindings + verbs: + - get + - list + - create + - update + - delete + - patch + - watch +--- +# Source: clabernetes/templates/clusterrole.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-launcher-role" + clabernetes/component: launcher-role + name: "clabernetes-launcher-role" +rules: + - apiGroups: + - clabernetes.containerlab.dev + resources: + - imagerequests + verbs: + - get + - create + - apiGroups: + - clabernetes.containerlab.dev + resources: + - connectivities + verbs: + - get + - watch diff --git a/charts/clabernetes/tests/customized_values/test-fixtures/golden/clusterrolebinding.yaml b/charts/clabernetes/tests/customized_values/test-fixtures/golden/clusterrolebinding.yaml new file mode 100755 index 0000000..e315e20 --- /dev/null +++ b/charts/clabernetes/tests/customized_values/test-fixtures/golden/clusterrolebinding.yaml @@ -0,0 +1,22 @@ +--- +# Source: clabernetes/templates/clusterrolebinding.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: clabernetes-manager + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-cluster-role-binding" + clabernetes/component: cluster-role-binding +subjects: + - kind: ServiceAccount + name: "clabernetes-service-account" + namespace: clabernetes +roleRef: + kind: ClusterRole + name: "clabernetes-cluster-role" + apiGroup: rbac.authorization.k8s.io diff --git a/charts/clabernetes/tests/customized_values/test-fixtures/golden/configmap.yaml b/charts/clabernetes/tests/customized_values/test-fixtures/golden/configmap.yaml new file mode 100755 index 0000000..029777b --- /dev/null +++ b/charts/clabernetes/tests/customized_values/test-fixtures/golden/configmap.yaml @@ -0,0 +1,38 @@ +--- +# Source: clabernetes/templates/configmap.yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: clabernetes-config + namespace: clabernetes + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-config" + clabernetes/component: config +data: + mergeMode: merge + globalAnnotations: |- + --- + {} + globalLabels: |- + --- + {} + resourcesDefault: |- + --- + requests: + cpu: 200m + memory: 512Mi + resourcesByContainerlabKind: |- + --- + {} + privilegedLauncher: "true" + containerlabDebug: "false" + inClusterDNSSuffix: svc.cluster.local + imagePullThroughMode: auto + launcherImagePullPolicy: IfNotPresent + launcherLogLevel: info + naming: prefixed diff --git a/charts/clabernetes/tests/customized_values/test-fixtures/golden/deployment.yaml b/charts/clabernetes/tests/customized_values/test-fixtures/golden/deployment.yaml new file mode 100755 index 0000000..fac93ea --- /dev/null +++ b/charts/clabernetes/tests/customized_values/test-fixtures/golden/deployment.yaml @@ -0,0 +1,134 @@ +--- +# Source: clabernetes/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: clabernetes-manager + namespace: clabernetes + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + app.kubernetes.io/name: "clabernetes-manager" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-manager" + clabernetes/component: manager +spec: + selector: + matchLabels: + clabernetes/app: clabernetes + release: release-name + replicas: 3 + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + app.kubernetes.io/name: "clabernetes-manager" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-manager" + clabernetes/component: manager + spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchLabels: + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-manager" + clabernetes/component: manager + topologyKey: kubernetes.io/hostname + - weight: 50 + podAffinityTerm: + labelSelector: + matchLabels: + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-manager" + clabernetes/component: manager + topologyKey: topology.kubernetes.io/zone + terminationGracePeriodSeconds: 10 + serviceAccountName: "clabernetes-service-account" + initContainers: + - name: init + image: "ghcr.io/srl-labs/clabernetes/clabernetes-manager:dev-latest" + imagePullPolicy: IfNotPresent + command: ["/clabernetes/manager", "run", "--initializer"] + env: + - name: APP_NAME + value: clabernetes + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: CLIENT_OPERATION_TIMEOUT_MULTIPLIER + value: "1" + - name: MANAGER_LOGGER_LEVEL + value: info + - name: CONTROLLER_LOGGER_LEVEL + value: info + - name: LAUNCHER_IMAGE + value: "ghcr.io/srl-labs/clabernetes/clabernetes-launcher:dev-latest" + resources: + requests: + memory: 128Mi + cpu: 50m + limits: + cpu: 100m + memory: 256Mi + containers: + - name: manager + image: "ghcr.io/srl-labs/clabernetes/clabernetes-manager:dev-latest" + imagePullPolicy: IfNotPresent + command: ["/clabernetes/manager", "run"] + env: + - name: APP_NAME + value: clabernetes + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: CLIENT_OPERATION_TIMEOUT_MULTIPLIER + value: "1" + - name: MANAGER_LOGGER_LEVEL + value: info + - name: CONTROLLER_LOGGER_LEVEL + value: info + - name: LAUNCHER_IMAGE + value: "ghcr.io/srl-labs/clabernetes/clabernetes-launcher:dev-latest" + resources: + requests: + memory: 128Mi + cpu: 50m + limits: + cpu: 100m + memory: 256Mi + ports: + - name: http + containerPort: 10443 + livenessProbe: + httpGet: + path: /alive + port: 10443 + scheme: HTTPS + successThreshold: 1 + failureThreshold: 2 + periodSeconds: 30 + timeoutSeconds: 5 diff --git a/charts/clabernetes/tests/customized_values/test-fixtures/golden/service.yaml b/charts/clabernetes/tests/customized_values/test-fixtures/golden/service.yaml new file mode 100755 index 0000000..d48a4e7 --- /dev/null +++ b/charts/clabernetes/tests/customized_values/test-fixtures/golden/service.yaml @@ -0,0 +1,27 @@ +--- +# Source: clabernetes/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: clabernetes-http + namespace: clabernetes + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-manager" + clabernetes/component: manager-http +spec: + type: ClusterIP + sessionAffinity: None + ports: + - name: https + port: 443 + protocol: TCP + targetPort: 10443 + selector: + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-manager" + clabernetes/component: manager diff --git a/charts/clabernetes/tests/customized_values/test-fixtures/golden/serviceaccount.yaml b/charts/clabernetes/tests/customized_values/test-fixtures/golden/serviceaccount.yaml new file mode 100755 index 0000000..4b1fbc0 --- /dev/null +++ b/charts/clabernetes/tests/customized_values/test-fixtures/golden/serviceaccount.yaml @@ -0,0 +1,15 @@ +--- +# Source: clabernetes/templates/serviceaccount.yaml +apiVersion: v1 +kind: ServiceAccount +metadata: + name: "clabernetes-service-account" + namespace: clabernetes + labels: + chart: "clabernetes-0.0.0" + release: release-name + heritage: Helm + revision: "1" + clabernetes/app: clabernetes + clabernetes/name: "clabernetes-service-account" + clabernetes/component: service-account diff --git a/charts/clabernetes/tests/default_values/test-fixtures/golden/configmap.yaml b/charts/clabernetes/tests/default_values/test-fixtures/golden/configmap.yaml index cf169a9..029777b 100755 --- a/charts/clabernetes/tests/default_values/test-fixtures/golden/configmap.yaml +++ b/charts/clabernetes/tests/default_values/test-fixtures/golden/configmap.yaml @@ -33,8 +33,6 @@ data: containerlabDebug: "false" inClusterDNSSuffix: svc.cluster.local imagePullThroughMode: auto - launcherImage: launcherImagePullPolicy: IfNotPresent launcherLogLevel: info naming: prefixed - containerlabVersion: diff --git a/charts/clicker/Chart.yaml b/charts/clicker/Chart.yaml index 383e08b..7175bb2 100644 --- a/charts/clicker/Chart.yaml +++ b/charts/clicker/Chart.yaml @@ -1,7 +1,7 @@ --- apiVersion: v2 name: clicker -description: Cl(aberntes t)ick(l)er! For "clicking" on some nodes to perform clabernetes related cluster wide sysctl commands. +description: Cl(abernetes t)ick(l)er! For "clicking" on some nodes to perform clabernetes related cluster wide sysctl commands. home: https://github.com/srl-labs/clabernetes sources: - https://github.com/srl-labs/clabernetes diff --git a/charts/clicker/tests/default_values/default_values_test.go b/charts/clicker/tests/default_values/default_values_test.go index 3e4a8be..9e5de3b 100644 --- a/charts/clicker/tests/default_values/default_values_test.go +++ b/charts/clicker/tests/default_values/default_values_test.go @@ -5,6 +5,7 @@ import ( "path/filepath" "testing" + clabernetesconstants "github.com/srl-labs/clabernetes/constants" clabernetestesthelper "github.com/srl-labs/clabernetes/testhelper" ) @@ -30,5 +31,12 @@ func TestDefaultValues(t *testing.T) { t.Log(chartsDir) - clabernetestesthelper.HelmTest(t, chartName, testName, "", "", chartsDir) + clabernetestesthelper.HelmTest( + t, + chartName, + testName, + clabernetesconstants.Clabernetes, + "", + chartsDir, + ) } diff --git a/testhelper/helm.go b/testhelper/helm.go index 8c932fd..d7aef49 100644 --- a/testhelper/helm.go +++ b/testhelper/helm.go @@ -22,14 +22,10 @@ const ( func HelmTest(t *testing.T, chartName, testName, namespace, valuesFileName, chartsDir string) { t.Helper() - // we have to make the chartname/templates dir too since thats where helm wants to write things - actualRootDir := fmt.Sprintf( - "%s/tests/%s/test-fixtures/%s-actual", - chartName, - testName, - testName, - ) - actualDir := fmt.Sprintf("%s/%s/templates", actualRootDir, chartName) + actualDir, err := filepath.Abs("actual") + if err != nil { + t.Fatalf("failed getting absolute path for actual dir, error: %s", err) + } var valuesFile string @@ -42,10 +38,10 @@ func HelmTest(t *testing.T, chartName, testName, namespace, valuesFileName, char ) } - err := os.MkdirAll(actualDir, clabernetesconstants.PermissionsEveryoneReadWriteOwnerExecute) + err = os.MkdirAll(actualDir, clabernetesconstants.PermissionsEveryoneReadWriteOwnerExecute) if err != nil { t.Fatalf( - "failed creating actual output directory %q, error: %s", actualDir, err, + "failed creating actual output directory, error: %s", err, ) } @@ -53,12 +49,12 @@ func HelmTest(t *testing.T, chartName, testName, namespace, valuesFileName, char if !*SkipCleanup { err = os.Chdir(chartsDir) if err != nil { - t.Logf("failed changing to a directory %q, error: %s", actualDir, err) + t.Logf("failed changing to a directory, error: %s", err) } - err = os.RemoveAll(actualRootDir) + err = os.RemoveAll(actualDir) if err != nil { - t.Logf("failed cleaning up actual output directory %q, error: %s", actualDir, err) + t.Logf("failed cleaning up actual output directory, error: %s", err) } } }() @@ -67,7 +63,7 @@ func HelmTest(t *testing.T, chartName, testName, namespace, valuesFileName, char "template", "./" + chartName, "--output-dir", - actualRootDir, + actualDir, } if namespace != "" { @@ -84,7 +80,7 @@ func HelmTest(t *testing.T, chartName, testName, namespace, valuesFileName, char args..., ) - renderedTemplates := ReadAllRenderedTemplates(t, actualRootDir) + renderedTemplates := ReadAllRenderedTemplates(t, actualDir) if *Update { for expectedFileName, expectedFileContent := range renderedTemplates { @@ -132,7 +128,7 @@ func ReadAllRenderedTemplates(t *testing.T, rootRenderDir string) map[string][]b renderedTemplates := map[string][]byte{} - parentChartFileNames, err := filepath.Glob(fmt.Sprintf("%s/*/templates/*.yaml", rootRenderDir)) + parentChartFileNames, err := filepath.Glob(fmt.Sprintf("/%s/*/templates/*.yaml", rootRenderDir)) if err != nil { t.Fatalf("failed globbing parent chart files, error: '%s'", err) } @@ -161,8 +157,7 @@ func ReadAllRenderedTemplates(t *testing.T, rootRenderDir string) map[string][]b for _, subChartFileName := range subChartFileNames { subChartPathComponents := strings.Split(subChartFileName, string(filepath.Separator)) - - subChartName := subChartPathComponents[4] + subChartName := subChartPathComponents[len(subChartPathComponents)-3] var contents []byte