|
6 | 6 | "io"
|
7 | 7 | "io/ioutil"
|
8 | 8 | "os"
|
| 9 | + "strings" |
9 | 10 |
|
10 | 11 | kerrors "k8s.io/apimachinery/pkg/api/errors"
|
11 | 12 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
@@ -68,6 +69,16 @@ func (o SecretOptions) Validate() error {
|
68 | 69 | return errors.New("KubeCoreClient must be present")
|
69 | 70 | }
|
70 | 71 |
|
| 72 | + // if any secret names are of the form <resource>/<name>, |
| 73 | + // ensure <resource> is a secret. |
| 74 | + for _, secretName := range o.SecretNames { |
| 75 | + if segs := strings.Split(secretName, "/"); len(segs) > 1 { |
| 76 | + if segs[0] != "secret" && segs[0] != "secrets" { |
| 77 | + return errors.New(fmt.Sprintf("expected resource of type secret, got %q", secretName)) |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
71 | 82 | return nil
|
72 | 83 | }
|
73 | 84 |
|
@@ -98,11 +109,22 @@ func (o SecretOptions) GetServiceAccount() (*kapi.ServiceAccount, error) {
|
98 | 109 | func (o SecretOptions) GetSecretNames(secrets []*kapi.Secret) sets.String {
|
99 | 110 | names := sets.String{}
|
100 | 111 | for _, secret := range secrets {
|
101 |
| - names.Insert(secret.Name) |
| 112 | + names.Insert(parseSecretName(secret.Name)) |
102 | 113 | }
|
103 | 114 | return names
|
104 | 115 | }
|
105 | 116 |
|
| 117 | +// parseSecretName receives a resource name as either |
| 118 | +// <resource type> / <name> or <name> and returns only the resource <name>. |
| 119 | +func parseSecretName(name string) string { |
| 120 | + segs := strings.Split(name, "/") |
| 121 | + if len(segs) < 2 { |
| 122 | + return name |
| 123 | + } |
| 124 | + |
| 125 | + return segs[1] |
| 126 | +} |
| 127 | + |
106 | 128 | // GetMountSecretNames Get a list of the names of the mount secrets associated
|
107 | 129 | // with a service account
|
108 | 130 | func (o SecretOptions) GetMountSecretNames(serviceaccount *kapi.ServiceAccount) sets.String {
|
|
0 commit comments