Skip to content

Commit

Permalink
Allow reading non default secrets (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: Deepak Kinni <[email protected]>
  • Loading branch information
Deepak Kinni committed Mar 4, 2021
1 parent d433214 commit 1326d2d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ func RetrievePlatformInfoFromConfig(config *rest.Config, params map[string]inter
return errors.Errorf("Failed to get k8s clientset from the given config: %v", config)
}
// Get the cluster flavor
var ns, secretData string
var ns string
clusterFlavor, err := GetClusterFlavor(config)
if clusterFlavor == TkgGuest || clusterFlavor == Unknown {
return errors.New("RetrieveVcConfigSecret: Cannot retrieve VC secret")
} else if clusterFlavor == Supervisor {
ns = VCSecretNsSupervisor
secretData = VCSecretDataSupervisor
} else {
ns = VCSecretNs
secretData = VCSecretData
}

secretApis := clientset.CoreV1().Secrets(ns)
Expand All @@ -96,8 +94,20 @@ func RetrievePlatformInfoFromConfig(config *rest.Config, params map[string]inter
return errors.Errorf("Failed to get k8s secret, %s", vsphere_secrets)
}

sEnc := string(secret.Data[secretData])
lines := strings.Split(sEnc, "\n")
// No kv pairs in the secret.
if len(secret.Data) == 0 {
return errors.Errorf("Failed to get k8s secret, %s", vsphere_secrets)
}

var sEnc string
var lines []string

for _, value := range secret.Data {
sEnc = string(value)
lines = strings.Split(sEnc, "\n")
// will always have only one kv pair.
break
}

for _, line := range lines {
if strings.Contains(line, "VirtualCenter") {
Expand Down

0 comments on commit 1326d2d

Please sign in to comment.