-
Notifications
You must be signed in to change notification settings - Fork 183
Turn the ClaimToken into a K8s Secret #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| {{- if not .Values.claimToken.secret -}} | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: {{ template "claimTokenSecretName" . }} | ||
| labels: | ||
| app: {{ template "name" . }} | ||
| chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} | ||
| release: {{ .Release.Name }} | ||
| heritage: {{ .Release.Service }} | ||
| type: Opaque | ||
| data: | ||
| {{ .Values.claimToken.secretKey }}: {{ .Values.claimToken.value | b64enc | quote }} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once the config for this is split into |
||
| {{- end -}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,12 @@ kubePlex: | |
| pullPolicy: Always | ||
|
|
||
| # Override this with the plex claim token from plex.tv/claim | ||
| claimToken: "" | ||
| claimToken: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to not break existing users, how about we leave this field as is, and add a new field: |
||
| ## secret containing your claimToken. if not set it will create a secret instead using claimToken.value | ||
| secret: | ||
| secretKey: claimToken | ||
| ## only specify value if you are passing in the plain text claimToken | ||
| value: | ||
|
|
||
| # Set the timezone of the plex server | ||
| timezone: Europe/London | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,11 +31,16 @@ var namespace = os.Getenv("KUBE_NAMESPACE") | |
| var pmsImage = os.Getenv("PMS_IMAGE") | ||
| var pmsInternalAddress = os.Getenv("PMS_INTERNAL_ADDRESS") | ||
|
|
||
| // the info about where the plex claim secret is held | ||
| // instead of passing the claim in plain text to the pods, we pass the secret | ||
| var plexClaimSecretName = os.Getenv("PLEX_CLAIM_SECRET_NAME") | ||
| var plexClaimSecretKey = os.Getenv("PLEX_CLAIM_SECRET_KEY") | ||
|
|
||
| func main() { | ||
| env := os.Environ() | ||
| args := os.Args | ||
|
|
||
| rewriteEnv(env) | ||
| env = rewriteEnv(env) | ||
| rewriteArgs(args) | ||
| cwd, err := os.Getwd() | ||
| if err != nil { | ||
|
|
@@ -83,9 +88,20 @@ func main() { | |
| } | ||
| } | ||
|
|
||
| func removeValFromEnvSlice(s []string, r string) []string { | ||
| for i, v := range s { | ||
| splitvar := strings.SplitN(v, "=", 2) | ||
| if splitvar[0] == r { | ||
| return append(s[:i], s[i+1:]...) | ||
| } | ||
| } | ||
| return s | ||
| } | ||
|
|
||
| // rewriteEnv rewrites environment variables to be passed to the transcoder | ||
| func rewriteEnv(in []string) { | ||
| // no changes needed | ||
| func rewriteEnv(in []string) []string { | ||
| in = removeValFromEnvSlice(in, "PLEX_CLAIM") | ||
| return in | ||
| } | ||
|
|
||
| func rewriteArgs(in []string) { | ||
|
|
@@ -101,6 +117,7 @@ func rewriteArgs(in []string) { | |
|
|
||
| func generatePod(cwd string, env []string, args []string) *corev1.Pod { | ||
| envVars := toCoreV1EnvVar(env) | ||
| envVars = addFromSecretsToCoreV1EnvVar(envVars) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think these values need to be set on the transcoder pods as the transcoder doesn't have to authenticate with PMS, as far as I am aware? 🤔 perhaps I am wrong though! It's been a while... |
||
| return &corev1.Pod{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| GenerateName: "pms-elastic-transcoder-", | ||
|
|
@@ -165,6 +182,23 @@ func generatePod(cwd string, env []string, args []string) *corev1.Pod { | |
| } | ||
| } | ||
|
|
||
| func addFromSecretsToCoreV1EnvVar(vars []corev1.EnvVar) []corev1.EnvVar { | ||
| secrets := []corev1.EnvVar{ | ||
| { | ||
| Name: "PLEX_CLAIM", | ||
| ValueFrom: &corev1.EnvVarSource{ | ||
| SecretKeyRef: &corev1.SecretKeySelector{ | ||
| LocalObjectReference: corev1.LocalObjectReference{ | ||
| Name: plexClaimSecretName, | ||
| }, | ||
| Key: plexClaimSecretKey, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| return append(vars, secrets...) | ||
| } | ||
|
|
||
| func toCoreV1EnvVar(in []string) []corev1.EnvVar { | ||
| out := make([]corev1.EnvVar, len(in)) | ||
| for i, v := range in { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 didn't realise these are incorrect 👀