Skip to content
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

PB-6687 : Add support for retrieving px secret env from stork deploy #1728

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkg/k8sutils/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const (
PxServiceEnvName = "PX_SERVICE_NAME"
// PxNamespaceEnvName - PX namespace ENV name
PxNamespaceEnvName = "PX_NAMESPACE"
// PxSecretIssuerEnvName - px secret issuer ENV name
PxSecretIssuerEnvName = "PX_JWT_ISSUER"
// PxSecretEnvName - px secret ENV name
PxSecretEnvName = "PX_SHARED_SECRET"
)

// JSONPatchOp is a single json mutation done by a k8s mutating webhook
Expand Down Expand Up @@ -389,3 +393,30 @@ func GetPxNamespaceFromStorkDeploy(storkDeployName, storkDeployNamespace string)
}
return namespace, service, nil
}

// GetPxSecretFromStorkDeploy - will return the px secret env from stork deploy used in nfs restore of secured portworx volumes
func GetPxSecretFromStorkDeploy(storkDeployName, storkDeployNamespace string) (string, string, error) {
deploy, err := apps.Instance().GetDeployment(storkDeployName, storkDeployNamespace)
if err != nil {
return "", "", err
}
var issuer, secretkey, secretvalue, secretData string
for _, envVar := range deploy.Spec.Template.Spec.Containers[0].Env {
if envVar.Name == PxSecretIssuerEnvName {
issuer = envVar.Value
}
if envVar.Name == PxSecretEnvName {
if envVar.ValueFrom != nil && envVar.ValueFrom.SecretKeyRef != nil {
secretkey = envVar.ValueFrom.SecretKeyRef.Key
secretvalue = envVar.ValueFrom.SecretKeyRef.Name
//Retrieving the secret value from the secret
secret, err := core.Instance().GetSecret(secretvalue, storkDeployNamespace)
if err != nil {
return "", "", err
}
secretData = string(secret.Data[secretkey])
}
}
}
return issuer, secretData, nil
}