Skip to content

Commit f053275

Browse files
committed
Makefile: remove dependency to envsubst binary
1 parent ab7948c commit f053275

File tree

4 files changed

+11
-28
lines changed

4 files changed

+11
-28
lines changed

Makefile

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ CONVERSION_GEN_BIN := conversion-gen
127127
CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN))
128128
CONVERSION_GEN_PKG := k8s.io/code-generator/cmd/conversion-gen
129129

130-
ENVSUBST_BIN := envsubst
131-
ENVSUBST_VER := $(call get_go_version,github.com/drone/envsubst/v2)
132-
ENVSUBST := $(abspath $(TOOLS_BIN_DIR)/$(ENVSUBST_BIN)-$(ENVSUBST_VER))
133-
ENVSUBST_PKG := github.com/drone/envsubst/v2/cmd/envsubst
134-
135130
GO_APIDIFF_VER := v0.8.2
136131
GO_APIDIFF_BIN := go-apidiff
137132
GO_APIDIFF := $(abspath $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER))
@@ -615,14 +610,14 @@ generate-e2e-templates-main: $(KUSTOMIZE)
615610
$(KUSTOMIZE) build $(INMEMORY_TEMPLATES)/main/cluster-template --load-restrictor LoadRestrictionsNone > $(INMEMORY_TEMPLATES)/main/cluster-template.yaml
616611

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

1415-
.PHONY: $(ENVSUBST_BIN)
1416-
$(ENVSUBST_BIN): $(ENVSUBST) ## Build a local copy of envsubst.
1417-
14181410
.PHONY: $(KUSTOMIZE_BIN)
14191411
$(KUSTOMIZE_BIN): $(KUSTOMIZE) ## Build a local copy of kustomize.
14201412

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

1476-
$(ENVSUBST): # Build gotestsum from tools folder.
1477-
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(ENVSUBST_PKG) $(ENVSUBST_BIN) $(ENVSUBST_VER)
1478-
14791468
$(KUSTOMIZE): # Build kustomize from tools folder.
14801469
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)
14811470

Tiltfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- mode: Python -*-
22

3-
envsubst_cmd = "./hack/tools/bin/envsubst"
43
clusterctl_cmd = "./bin/clusterctl"
54
kubectl_cmd = "kubectl"
65
kubernetes_version = "v1.31.2"
@@ -498,7 +497,7 @@ def deploy_additional_kustomizations():
498497
)
499498

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

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

554553
def deploy_clusterclass(clusterclass_name, label, filename, substitutions):
555-
apply_clusterclass_cmd = "cat " + filename + " | " + envsubst_cmd + " | " + kubectl_cmd + " apply --namespace=$NAMESPACE -f - && echo \"ClusterClass created from\'" + filename + "\', don't forget to delete\n\""
554+
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\""
556555
delete_clusterclass_cmd = kubectl_cmd + " --namespace=$NAMESPACE delete clusterclass " + clusterclass_name + ' --ignore-not-found=true; echo "\n"'
557556

558557
local_resource(

hack/tools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ require (
8989
github.com/docker/docker v27.5.1+incompatible // indirect
9090
github.com/docker/go-connections v0.5.0 // indirect
9191
github.com/docker/go-units v0.4.0 // indirect
92-
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
92+
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46
9393
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
9494
github.com/emirpasic/gods v1.18.1 // indirect
9595
github.com/evanphx/json-patch/v5 v5.9.10 // indirect

hack/tools/internal/tilt-prepare/main.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"sync"
3535
"time"
3636

37+
"github.com/drone/envsubst/v2"
3738
"github.com/pkg/errors"
3839
"github.com/spf13/pflag"
3940
appsv1 "k8s.io/api/apps/v1"
@@ -61,12 +62,11 @@ import (
6162

6263
/*
6364
Example call for tilt up:
64-
--tools kustomize,envsubst
65+
--tools kustomize,clusterctl
6566
*/
6667

6768
const (
6869
kustomizePath = "./hack/tools/bin/kustomize"
69-
envsubstPath = "./hack/tools/bin/envsubst"
7070
)
7171

7272
var (
@@ -718,18 +718,13 @@ func workloadTask(name, workloadType, binaryName, containerName string, liveRelo
718718
return
719719
}
720720

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

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

0 commit comments

Comments
 (0)