Skip to content

Commit

Permalink
Lookup the dynamic configmap name instead of 'replicated' (#88)
Browse files Browse the repository at this point in the history
* Lookup the dynamic configmap name instead of 'replicated'
  • Loading branch information
sgalsaleh authored Sep 7, 2023
1 parent 1e3010b commit bbcd099
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
4 changes: 0 additions & 4 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ Is OpenShift
{{/*
Resource Names
*/}}
{{- define "replicated.configMapName" -}}
{{ include "replicated.name" . }}
{{- end -}}

{{- define "replicated.deploymentName" -}}
{{ include "replicated.name" . }}
{{- end -}}
Expand Down
8 changes: 4 additions & 4 deletions chart/templates/replicated-configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{{/*
This is a legacy/deprecated configmap.
The replicated API will use the deployment uid as the app-id and replicated-id if the configmap does not exist.
The replicated API will use the deployment uid if the configmap does not exist.
*/}}
{{- $data := (lookup "v1" "ConfigMap" .Release.Namespace "replicated").data }}
{{- $data := (lookup "v1" "ConfigMap" .Release.Namespace "replicated-sdk").data }}
{{- if $data }}
apiVersion: v1
kind: ConfigMap
metadata:
labels:
{{- include "replicated.labels" . | nindent 4 }}
name: {{ include "replicated.configMapName" . }}
name: replicated-sdk
namespace: {{ include "replicated.namespace" . | quote }}
data:
replicated-id: {{ index $data "replicated-id" }}
replicated-sdk-id: {{ index $data "replicated-sdk-id" }}
app-id: {{ index $data "app-id" }}
{{- end }}
2 changes: 0 additions & 2 deletions chart/templates/replicated-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ spec:
value: secret # TODO: support other drivers
- name: REPLICATED_SECRET_NAME
value: {{ include "replicated.secretName" . }}
- name: REPLICATED_CONFIGMAP_NAME
value: {{ include "replicated.configMapName" . }}
- name: REPLICATED_DEPLOYMENT_NAME
value: {{ include "replicated.deploymentName" . }}
- name: REPLICATED_CONFIG_FILE
Expand Down
17 changes: 7 additions & 10 deletions pkg/util/replicated.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func GetLegacyReplicatedConfigMapName() string {
return "replicated-sdk"
}

func GetReplicatedSecretName() string {
if sn := os.Getenv("REPLICATED_SECRET_NAME"); sn != "" {
return sn
}
return "replicated"
}

func GetReplicatedConfigMapName() string {
if cmn := os.Getenv("REPLICATED_CONFIGMAP_NAME"); cmn != "" {
return cmn
}
return "replicated"
}

func GetReplicatedDeploymentName() string {
if dn := os.Getenv("REPLICATED_DEPLOYMENT_NAME"); dn != "" {
return dn
Expand All @@ -45,9 +42,9 @@ func GetReplicatedAndAppIDs(namespace string) (string, string, error) {
return "", "", errors.Wrap(err, "failed to get clientset")
}

cm, err := clientset.CoreV1().ConfigMaps(namespace).Get(context.TODO(), GetReplicatedConfigMapName(), metav1.GetOptions{})
cm, err := clientset.CoreV1().ConfigMaps(namespace).Get(context.TODO(), GetLegacyReplicatedConfigMapName(), metav1.GetOptions{})
if err != nil && !kuberneteserrors.IsNotFound(err) {
return "", "", errors.Wrap(err, "failed to get replicated configmap")
return "", "", errors.Wrap(err, "failed to get replicated-sdk configmap")
}

replicatedID := ""
Expand All @@ -61,7 +58,7 @@ func GetReplicatedAndAppIDs(namespace string) (string, string, error) {
replicatedID = string(d.ObjectMeta.UID)
appID = string(d.ObjectMeta.UID)
} else {
replicatedID = cm.Data["replicated-id"]
replicatedID = cm.Data["replicated-sdk-id"]
appID = cm.Data["app-id"]
}

Expand Down

0 comments on commit bbcd099

Please sign in to comment.