Skip to content

Commit

Permalink
tidy: make envvars consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyzimmer committed Oct 2, 2023
1 parent 4baafe0 commit d5cbca6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ data:
"kubeconfig": "__KUBECONFIG_FILEPATH__",
"nodeName": "__KUBERNETES_NODE_NAME__",
"k8sAPIRoot": "__KUBERNETES_API_ENDPOINT__"
"namespace": "__K8S_POD_NAMESPACE__"
"namespace": "__KUBERNETES_POD_NAMESPACE__"
}
}
]
Expand Down Expand Up @@ -1035,7 +1035,7 @@ spec:
fieldRef:
fieldPath: spec.nodeName
# Set the namespace to use based on the one we are running.
- name: K8S_POD_NAMESPACE
- name: KUBERNETES_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
Expand Down Expand Up @@ -1067,7 +1067,7 @@ spec:
fieldRef:
fieldPath: spec.nodeName
# Set the namespace to use based on the one we are running.
- name: K8S_POD_NAMESPACE
- name: KUBERNETES_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
Expand Down
6 changes: 3 additions & 3 deletions deploy/cni/cni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data:
"kubeconfig": "__KUBECONFIG_FILEPATH__",
"nodeName": "__KUBERNETES_NODE_NAME__",
"k8sAPIRoot": "__KUBERNETES_API_ENDPOINT__"
"namespace": "__K8S_POD_NAMESPACE__"
"namespace": "__KUBERNETES_POD_NAMESPACE__"
}
}
]
Expand Down Expand Up @@ -91,7 +91,7 @@ spec:
fieldRef:
fieldPath: spec.nodeName
# Set the namespace to use based on the one we are running.
- name: K8S_POD_NAMESPACE
- name: KUBERNETES_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
Expand Down Expand Up @@ -123,7 +123,7 @@ spec:
fieldRef:
fieldPath: spec.nodeName
# Set the namespace to use based on the one we are running.
- name: K8S_POD_NAMESPACE
- name: KUBERNETES_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
Expand Down
20 changes: 14 additions & 6 deletions internal/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ const (
// BinaryDestConfEnvVar is the destination directory for the CNI configuration.
BinaryDestConfEnvVar = "CNI_CONF_DIR"
// PodNamespaceEnvVar is the name of the environment variable that contains the pod namespace.
PodNamespaceEnvVar = "K8S_POD_NAMESPACE"
PodNamespaceEnvVar = "KUBERNETES_POD_NAMESPACE"
// NodeNameReplaceStr is the string that will be replaced in the CNI configuration with the node name.
NodeNameReplaceStr = "__KUBERNETES_NODE_NAME__"
// PodNamespaceReplaceStr is the string that will be replaced in the CNI configuration with the pod namespace.
PodNamespaceReplaceStr = "__KUBERNETES_POD_NAMESPACE__"
// KubeAPIEndpointReplaceStr is the string that will be replaced in the CNI configuration with the Kubernetes API endpoint.
APIEndpointReplaceStr = "__KUBERNETES_API_ENDPOINT__"
// KubeconfigFilepathReplaceStr is the string that will be replaced in the CNI configuration with the kubeconfig filepath.
KubeconfigFilepathReplaceStr = "__KUBECONFIG_FILEPATH__"
// PluginBinaryName is the name of the plugin binary.
PluginBinaryName = "webmesh"
)
Expand Down Expand Up @@ -108,13 +116,13 @@ func Main(version string) {
}
// Do necessary string replacements on the CNI configuration.
conf := os.Getenv(NetConfEnvVar)
conf = strings.Replace(conf, "__KUBERNETES_NODE_NAME__", os.Getenv(NodeNameEnvVar), -1)
conf = strings.Replace(conf, "__K8S_POD_NAMESPACE__", os.Getenv(PodNamespaceEnvVar), -1)
conf = strings.Replace(conf, "__KUBERNETES_API_ENDPOINT__", cfg.Host, -1)
conf = strings.Replace(conf, "__KUBECONFIG_FILEPATH__", kubeconfigPath, -1)
conf = strings.Replace(conf, NodeNameReplaceStr, os.Getenv(NodeNameEnvVar), -1)
conf = strings.Replace(conf, PodNamespaceReplaceStr, os.Getenv(PodNamespaceEnvVar), -1)
conf = strings.Replace(conf, APIEndpointReplaceStr, cfg.Host, -1)
conf = strings.Replace(conf, KubeconfigFilepathReplaceStr, kubeconfigPath, -1)
// Write the CNI configuration to the destination directory.
confPath := filepath.Join(os.Getenv(BinaryDestConfEnvVar), os.Getenv(NetConfFileNameEnvVar))
log.Println("Effective CNI configuration -> ")
log.Println("effective CNI configuration -> ")
fmt.Println(conf)
log.Println("installing CNI configuration to -> ", confPath)
if err := os.WriteFile(confPath, []byte(conf), 0644); err != nil {
Expand Down

0 comments on commit d5cbca6

Please sign in to comment.