Skip to content

Commit

Permalink
Merge pull request #11783 from chrischdi/pr-remove-envsubst
Browse files Browse the repository at this point in the history
🌱 remove dependency to envsubst binary
  • Loading branch information
k8s-ci-robot authored Feb 3, 2025
2 parents 920ee7d + f053275 commit 934e159
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 28 deletions.
15 changes: 2 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ CONVERSION_GEN_BIN := conversion-gen
CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN))
CONVERSION_GEN_PKG := k8s.io/code-generator/cmd/conversion-gen

ENVSUBST_BIN := envsubst
ENVSUBST_VER := $(call get_go_version,github.com/drone/envsubst/v2)
ENVSUBST := $(abspath $(TOOLS_BIN_DIR)/$(ENVSUBST_BIN)-$(ENVSUBST_VER))
ENVSUBST_PKG := github.com/drone/envsubst/v2/cmd/envsubst

GO_APIDIFF_VER := v0.8.2
GO_APIDIFF_BIN := go-apidiff
GO_APIDIFF := $(abspath $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER))
Expand Down Expand Up @@ -615,14 +610,14 @@ generate-e2e-templates-main: $(KUSTOMIZE)
$(KUSTOMIZE) build $(INMEMORY_TEMPLATES)/main/cluster-template --load-restrictor LoadRestrictionsNone > $(INMEMORY_TEMPLATES)/main/cluster-template.yaml

.PHONY: generate-metrics-config
generate-metrics-config: $(ENVSUBST_BIN) ## Generate ./config/metrics/crd-metrics-config.yaml
generate-metrics-config: ## Generate ./config/metrics/crd-metrics-config.yaml
OUTPUT_FILE="./config/metrics/crd-metrics-config.yaml"; \
METRIC_TEMPLATES_DIR="./config/metrics/templates"; \
echo "# This file was auto-generated via: make generate-metrics-config" > "$${OUTPUT_FILE}"; \
cat "$${METRIC_TEMPLATES_DIR}/header.yaml" >> "$${OUTPUT_FILE}"; \
for resource in clusterclass cluster kubeadmcontrolplane kubeadmconfig machine machinedeployment machinehealthcheck machineset machinepool; do \
cat "$${METRIC_TEMPLATES_DIR}/$${resource}.yaml"; \
RESOURCE="$${resource}" ${ENVSUBST_BIN} < "$${METRIC_TEMPLATES_DIR}/common_metrics.yaml"; \
sed 's/$${RESOURCE}/'$${resource}'/g' "$${METRIC_TEMPLATES_DIR}/common_metrics.yaml"; \
if [[ "$${resource}" != "cluster" ]]; then \
cat "$${METRIC_TEMPLATES_DIR}/owner_metric.yaml"; \
fi \
Expand Down Expand Up @@ -1412,9 +1407,6 @@ $(GOTESTSUM_BIN): $(GOTESTSUM) ## Build a local copy of gotestsum.
.PHONY: $(GO_APIDIFF_BIN)
$(GO_APIDIFF_BIN): $(GO_APIDIFF) ## Build a local copy of go-apidiff

.PHONY: $(ENVSUBST_BIN)
$(ENVSUBST_BIN): $(ENVSUBST) ## Build a local copy of envsubst.

.PHONY: $(KUSTOMIZE_BIN)
$(KUSTOMIZE_BIN): $(KUSTOMIZE) ## Build a local copy of kustomize.

Expand Down Expand Up @@ -1473,9 +1465,6 @@ $(GOTESTSUM): # Build gotestsum from tools folder.
$(GO_APIDIFF): # Build go-apidiff from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GO_APIDIFF_PKG) $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)

$(ENVSUBST): # Build gotestsum from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(ENVSUBST_PKG) $(ENVSUBST_BIN) $(ENVSUBST_VER)

$(KUSTOMIZE): # Build kustomize from tools folder.
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)

Expand Down
5 changes: 2 additions & 3 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- mode: Python -*-

envsubst_cmd = "./hack/tools/bin/envsubst"
clusterctl_cmd = "./bin/clusterctl"
kubectl_cmd = "kubectl"
kubernetes_version = "v1.31.2"
Expand Down Expand Up @@ -498,7 +497,7 @@ def deploy_additional_kustomizations():
)

def prepare_all():
tools_arg = "--tools kustomize,envsubst,clusterctl "
tools_arg = "--tools kustomize,clusterctl "
tilt_settings_file_arg = "--tilt-settings-file " + tilt_file

cmd = "make -B tilt-prepare && ./hack/tools/bin/tilt-prepare {tools_arg}{tilt_settings_file_arg}".format(
Expand Down Expand Up @@ -552,7 +551,7 @@ def deploy_templates(filename, label, substitutions):
deploy_cluster_template(template_name, label, filename, substitutions)

def deploy_clusterclass(clusterclass_name, label, filename, substitutions):
apply_clusterclass_cmd = "cat " + filename + " | " + envsubst_cmd + " | " + kubectl_cmd + " apply --namespace=$NAMESPACE -f - && echo \"ClusterClass created from\'" + filename + "\', don't forget to delete\n\""
apply_clusterclass_cmd = clusterctl_cmd + " generate yaml --from " + filename + " | " + kubectl_cmd + " apply --namespace=$NAMESPACE -f - && echo \"ClusterClass created from\'" + filename + "\', don't forget to delete\n\""
delete_clusterclass_cmd = kubectl_cmd + " --namespace=$NAMESPACE delete clusterclass " + clusterclass_name + ' --ignore-not-found=true; echo "\n"'

local_resource(
Expand Down
2 changes: 1 addition & 1 deletion hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ require (
github.com/docker/docker v27.5.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.10 // indirect
Expand Down
17 changes: 6 additions & 11 deletions hack/tools/internal/tilt-prepare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"sync"
"time"

"github.com/drone/envsubst/v2"
"github.com/pkg/errors"
"github.com/spf13/pflag"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -61,12 +62,11 @@ import (

/*
Example call for tilt up:
--tools kustomize,envsubst
--tools kustomize,clusterctl
*/

const (
kustomizePath = "./hack/tools/bin/kustomize"
envsubstPath = "./hack/tools/bin/envsubst"
)

var (
Expand Down Expand Up @@ -718,18 +718,13 @@ func workloadTask(name, workloadType, binaryName, containerName string, liveRelo
return
}

envsubstCmd := exec.CommandContext(ctx, envsubstPath)
var stdout2, stderr2 bytes.Buffer
envsubstCmd.Dir = rootPath
envsubstCmd.Stdin = bytes.NewReader(stdout1.Bytes())
envsubstCmd.Stdout = &stdout2
envsubstCmd.Stderr = &stderr2
if err := envsubstCmd.Run(); err != nil {
errCh <- errors.Wrapf(err, "[%s] failed to run %s: %s", prefix, envsubstCmd.Args, stderr2.String())
out2, err := envsubst.Eval(stdout1.String(), os.Getenv)
if err != nil {
errCh <- errors.Wrapf(err, "[%s] failed to do envsubst on kustomized output", prefix)
return
}

objs, err := utilyaml.ToUnstructured(stdout2.Bytes())
objs, err := utilyaml.ToUnstructured([]byte(out2))
if err != nil {
errCh <- errors.Wrapf(err, "[%s] failed parse components yaml", prefix)
return
Expand Down

0 comments on commit 934e159

Please sign in to comment.