Skip to content

Commit

Permalink
Remove unnecessary "kind" check in SecretRef
Browse files Browse the repository at this point in the history
The ActionSet schema allows specifying secret refs under
the "secrets" key.

This commit removes the requirement that the user specify
a `Kind` in the reference because that information is not
required.
  • Loading branch information
Vaibhav Kamra committed Aug 22, 2019
1 parent a418c71 commit 4b4059a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 12 additions & 4 deletions pkg/param/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,20 @@ func fetchKeyPairCredential(ctx context.Context, cli kubernetes.Interface, c *cr
}, nil
}

func fetchSecrets(ctx context.Context, cli kubernetes.Interface, refs map[string]crv1alpha1.ObjectReference) (map[string]v1.Secret, error) {
secrets := make(map[string]v1.Secret, len(refs))
func filterByKind(refs map[string]crv1alpha1.ObjectReference, kind string) map[string]crv1alpha1.ObjectReference {
filtered := make(map[string]crv1alpha1.ObjectReference, len(refs))
for name, ref := range refs {
if strings.ToLower(ref.Kind) != SecretKind {
if strings.ToLower(ref.Kind) != strings.ToLower(kind) {
continue
}
filtered[name] = ref
}
return filtered
}

func fetchSecrets(ctx context.Context, cli kubernetes.Interface, refs map[string]crv1alpha1.ObjectReference) (map[string]v1.Secret, error) {
secrets := make(map[string]v1.Secret, len(refs))
for name, ref := range refs {
s, err := cli.CoreV1().Secrets(ref.Namespace).Get(ref.Name, metav1.GetOptions{})
if err != nil {
return nil, errors.WithStack(err)
Expand Down Expand Up @@ -343,7 +351,7 @@ func InitPhaseParams(ctx context.Context, cli kubernetes.Interface, tp *Template
if tp.Phases == nil {
tp.Phases = make(map[string]*Phase)
}
secrets, err := fetchSecrets(ctx, cli, objects)
secrets, err := fetchSecrets(ctx, cli, filterByKind(objects, SecretKind))
if err != nil {
return err
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/param/param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/Masterminds/sprig"
. "gopkg.in/check.v1"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -521,7 +521,7 @@ func (s *ParamsSuite) TestPhaseParams(c *C) {
},
},
}
_, err := s.cli.CoreV1().Secrets(s.namespace).Create(secret)
secret, err := s.cli.CoreV1().Secrets(s.namespace).Create(secret)
c.Assert(err, IsNil)
defer s.cli.CoreV1().Secrets(s.namespace).Delete("secret-name", &metav1.DeleteOptions{})

Expand All @@ -543,6 +543,12 @@ func (s *ParamsSuite) TestPhaseParams(c *C) {
Name: "profName",
Namespace: s.namespace,
},
Secrets: map[string]crv1alpha1.ObjectReference{
"actionSetSecret": crv1alpha1.ObjectReference{
Name: secret.Name,
Namespace: secret.Namespace,
},
},
}
tp, err := New(ctx, s.cli, crCli, as)
c.Assert(err, IsNil)
Expand All @@ -552,6 +558,8 @@ func (s *ParamsSuite) TestPhaseParams(c *C) {
UpdatePhaseParams(ctx, tp, "backup", map[string]interface{}{"version": "0.20.0"})
c.Assert(tp.Phases, HasLen, 1)
c.Assert(tp.Phases["backup"], NotNil)
c.Assert(tp.Secrets, HasLen, 1)
c.Assert(tp.Secrets["actionSetSecret"], DeepEquals, *secret)
}

func (s *ParamsSuite) TestRenderingPhaseParams(c *C) {
Expand Down

0 comments on commit 4b4059a

Please sign in to comment.