This repository was archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: get helm config from a well known configmap #27
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fd2a24f
ci: adds tooling to create configmap
faiq 66c97c0
feat: use a configmap to get helmchart info
faiq c8d2b14
fix: precommit issues
faiq 30bf963
fix: typo in cilium
faiq 08b1073
fix: remove workspace files
faiq 72e5b41
build: template name for configmap
faiq 58f19ec
refactor: names for helm chart info getter
faiq 7db9979
refactor: use nutanix-storage name instead of nutnaix-csi
faiq 68b9c3c
refactor: move to globaloptions
faiq 8541f01
fix: adds snapshot to helm config
faiq 80368c0
fix: comments after review
faiq 8ad9ab4
fix: adds a warning and removes ebs csi
faiq 31783f7
fix: typo
faiq 44585c3
fix: adds missing script file
faiq eba2351
fix: precommit
faiq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2023 D2iQ, Inc. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#================================================================= | ||
# DO NOT EDIT THIS FILE | ||
# IT HAS BEEN GENERATED BY /hack/tools/helm-cm/main.go | ||
#================================================================= | ||
apiVersion: v1 | ||
faiq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data: | ||
cilium: | | ||
ChartName: cilium | ||
ChartVersion: 1.15.0 | ||
RepositoryURL: https://helm.cilium.io/ | ||
cluster-autoscaler: | | ||
ChartName: cluster-autoscaler | ||
ChartVersion: 9.35.0 | ||
RepositoryURL: https://kubernetes.github.io/autoscaler | ||
nfd: | | ||
ChartName: node-feature-discovery | ||
ChartVersion: 0.15.2 | ||
RepositoryURL: https://kubernetes-sigs.github.io/node-feature-discovery/charts | ||
nutanix-snapshot-csi: | | ||
ChartName: nutanix-csi-snapshot | ||
ChartVersion: v6.3.2 | ||
RepositoryURL: https://nutanix.github.io/helm/ | ||
nutanix-storage-csi: | | ||
ChartName: nutanix-csi-storage | ||
ChartVersion: v2.6.6 | ||
RepositoryURL: https://nutanix.github.io/helm/ | ||
tigera-operator: | | ||
ChartName: tigera-operator | ||
ChartVersion: v3.26.4 | ||
RepositoryURL: https://docs.tigera.io/calico/charts | ||
kind: ConfigMap | ||
metadata: | ||
creationTimestamp: null | ||
name: {{ .Values.helmAddonsConfigMap }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
readonly SCRIPT_DIR | ||
|
||
# shellcheck source=hack/common.sh | ||
source "${SCRIPT_DIR}/../common.sh" | ||
ASSETS_DIR="$(mktemp -d -p "${TMPDIR:-/tmp}")" | ||
mv "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" "${ASSETS_DIR}/helm-config.yaml" | ||
# add warning not to edit file directly | ||
cat <<EOF >"${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" | ||
$(cat "${GIT_REPO_ROOT}/hack/license-header.yaml.txt") | ||
|
||
#================================================================= | ||
# DO NOT EDIT THIS FILE | ||
# IT HAS BEEN GENERATED BY /hack/tools/helm-cm/main.go | ||
#================================================================= | ||
$(cat "${ASSETS_DIR}/helm-config.yaml") | ||
EOF | ||
|
||
sed -i s/placeholder/"{{ .Values.helmAddonsConfigMap }}"/g "${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml" |
19 changes: 19 additions & 0 deletions
19
hack/addons/kustomize/nutanix-snapshot-csi/kustomization.yaml.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2023 D2iQ, Inc. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
metadata: | ||
name: nutanix-csi-kustomize | ||
|
||
namespace: kube-system | ||
|
||
helmCharts: | ||
- name: nutanix-csi-snapshot | ||
repo: https://nutanix.github.io/helm/ | ||
releaseName: nutanix-csi-storage | ||
version: ${NUTANIX_SNAPSHOT_CSI_CHART_VERSION} | ||
includeCRDs: true | ||
skipTests: true | ||
namespace: nutanix-system |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// Copyright 2023 D2iQ, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"flag" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path" | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/yaml" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
yamlMarshal "sigs.k8s.io/yaml" | ||
) | ||
|
||
const ( | ||
createHelmAddonsConfigMap = "helm-addons" | ||
) | ||
|
||
var log = ctrl.LoggerFrom(context.Background()) | ||
|
||
func main() { | ||
args := os.Args | ||
var ( | ||
kustomizeDirectory string | ||
outputFile string | ||
) | ||
flagSet := flag.NewFlagSet(createHelmAddonsConfigMap, flag.ExitOnError) | ||
flagSet.StringVar(&kustomizeDirectory, "kustomize-directory", "", | ||
"Kustomize base directory for all addons") | ||
flagSet.StringVar(&outputFile, "output-file", "", | ||
"output file name to write config map to.") | ||
err := flagSet.Parse(args[1:]) | ||
if err != nil { | ||
log.Error(err, "failed to parse args") | ||
} | ||
cm, err := createConfigMapFromDir(kustomizeDirectory) | ||
if err != nil { | ||
log.Error(err, "failed to create configMap") | ||
return | ||
} | ||
b, err := yamlMarshal.Marshal(*cm) | ||
if err != nil { | ||
log.Error(err, "failed ") | ||
} | ||
fullOutputfilePath := outputFile | ||
if !path.IsAbs(outputFile) { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
log.Error(err, "failed") | ||
} | ||
fullOutputfilePath = path.Join(wd, outputFile) | ||
} | ||
f, err := os.OpenFile(fullOutputfilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o666) | ||
if err != nil { | ||
log.Error(err, "failed to create file") | ||
} | ||
defer f.Close() | ||
_, err = bytes.NewBuffer(b).WriteTo(f) | ||
if err != nil { | ||
log.Error(err, "failed to write to file") | ||
} | ||
} | ||
|
||
type configMapInfo struct { | ||
configMapFieldName string | ||
RepositoryURL string `json:"RepositoryURL"` | ||
ChartVersion string `json:"ChartVersion"` | ||
ChartName string `json:"ChartName"` | ||
} | ||
|
||
func createConfigMapFromDir(kustomizeDir string) (*corev1.ConfigMap, error) { | ||
fullPath := kustomizeDir | ||
if !path.IsAbs(fullPath) { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get wd %w", err) | ||
} | ||
fullPath = path.Join(wd, kustomizeDir) | ||
} | ||
configDirFS := os.DirFS(fullPath) | ||
results := []configMapInfo{} | ||
err := fs.WalkDir(configDirFS, ".", func(filepath string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if strings.Contains(filepath, "kustomization.yaml.tmpl") && !isIgnored(filepath) { | ||
f, err := os.Open(path.Join(fullPath, filepath)) | ||
if err != nil { | ||
return fmt.Errorf("failed to open file: %w", err) | ||
} | ||
defer f.Close() | ||
obj := make(map[string]interface{}) | ||
err = yaml.NewYAMLOrJSONDecoder(f, 1024).Decode(&obj) | ||
if err != nil { | ||
return err | ||
} | ||
charts, ok := obj["helmCharts"] | ||
if !ok { | ||
log.Info("obj %v does not have field helmCharts. skipping \n", obj) | ||
return nil | ||
} | ||
parsedCharts, ok := charts.([]interface{}) | ||
if !ok { | ||
return fmt.Errorf("charts obj %v is not of type []interface", charts) | ||
} | ||
info, ok := parsedCharts[0].(map[string]interface{}) | ||
if !ok { | ||
return fmt.Errorf("info obj %v is not of type map[string]interface", parsedCharts) | ||
} | ||
repo := info["repo"].(string) | ||
name := info["name"].(string) | ||
dirName := strings.Split(filepath, "/")[0] | ||
i := configMapInfo{ | ||
configMapFieldName: dirName, | ||
RepositoryURL: repo, | ||
ChartName: name, | ||
} | ||
versionEnvVar := info["version"].(string) | ||
version := os.ExpandEnv(versionEnvVar) | ||
i.ChartVersion = version | ||
results = append(results, i) | ||
return nil | ||
} | ||
return nil | ||
}) | ||
|
||
finalCM := corev1.ConfigMap{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "placeholder", | ||
}, | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: corev1.SchemeGroupVersion.String(), | ||
Kind: "ConfigMap", | ||
}, | ||
Data: make(map[string]string), | ||
} | ||
for _, res := range results { | ||
d, err := yamlMarshal.Marshal(res) | ||
if err != nil { | ||
return &finalCM, err | ||
} | ||
finalCM.Data[res.configMapFieldName] = string(d) | ||
} | ||
return &finalCM, err | ||
} | ||
|
||
var ignored = []string{ | ||
"aws-ccm", | ||
"aws-ebs-csi", | ||
} | ||
|
||
func isIgnored(filepath string) bool { | ||
for _, i := range ignored { | ||
if strings.Contains(filepath, i) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.