-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add genruntime support for Dynamic secrets and configmap exports (#4314)
- Loading branch information
Showing
10 changed files
with
428 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package configmaps | ||
|
||
import ( | ||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/core" | ||
) | ||
|
||
// Exporter defines an interface for exporting ConfigMaps based on CEL expressions. | ||
type Exporter interface { | ||
ConfigMapDestinationExpressions() []*core.DestinationExpression | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT license. | ||
*/ | ||
|
||
package configmaps_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
|
||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime" | ||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/configmaps" | ||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/core" | ||
) | ||
|
||
func Test_ValidateConfigMapDestination_EmptyListValidates(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(nil, nil) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} | ||
|
||
func Test_ValidateConfigMapDestination_ListWithNilElementsValidates(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*genruntime.ConfigMapDestination{ | ||
nil, | ||
nil, | ||
} | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(destinations, nil) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} | ||
|
||
func Test_ValidateConfigMapDestinationExpressions_ListWithNilElementsValidates(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*core.DestinationExpression{ | ||
nil, | ||
nil, | ||
} | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(nil, destinations) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} | ||
|
||
func Test_ValidateConfigMapDestination_LengthOneListValidates(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*genruntime.ConfigMapDestination{ | ||
{Name: "n1", Key: "key1"}, | ||
} | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(destinations, nil) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} | ||
|
||
func Test_ValidateConfigMapDestinationExpressions_LengthOneListValidates(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*core.DestinationExpression{ | ||
{Name: "n1", Key: "key1", Value: "resource.status.id"}, | ||
} | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(nil, destinations) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} | ||
|
||
func Test_ValidateConfigMapDestination_ListWithoutCollisionsValidates(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*genruntime.ConfigMapDestination{ | ||
{Name: "n1", Key: "key1"}, | ||
{Name: "n1", Key: "key2"}, | ||
{Name: "n1", Key: "key3"}, | ||
{Name: "n1", Key: "key4"}, | ||
} | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(destinations, nil) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} | ||
|
||
func Test_ValidateConfigMapDestinationExpressions_ListWithoutCollisionsValidates(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*core.DestinationExpression{ | ||
{Name: "n1", Key: "key1", Value: "resource.status.id"}, | ||
{Name: "n1", Key: "key2", Value: "resource.status.id"}, | ||
{Name: "n1", Key: "key3", Value: "resource.status.id"}, | ||
{Name: "n1", Key: "key4", Value: "resource.status.id"}, | ||
} | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(nil, destinations) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} | ||
|
||
func Test_ValidateConfigMapDestination_ListWithDifferentCasesValidates(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*genruntime.ConfigMapDestination{ | ||
{Name: "n1", Key: "key1"}, | ||
{Name: "n1", Key: "Key1"}, | ||
{Name: "n1", Key: "key3"}, | ||
{Name: "n1", Key: "key4"}, | ||
} | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(destinations, nil) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} | ||
|
||
func Test_ValidateConfigMapDestination_ListWithCollisionsFailsValidation(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*genruntime.ConfigMapDestination{ | ||
{Name: "n1", Key: "key1"}, | ||
{Name: "n2", Key: "key1"}, | ||
{Name: "n3", Key: "key1"}, | ||
{Name: "n1", Key: "key1"}, | ||
} | ||
_, err := configmaps.ValidateDestinationsExt(destinations, nil) | ||
g.Expect(err).ToNot(BeNil()) | ||
g.Expect(err.Error()).To(Equal("cannot write more than one configmap value to destination Name: \"n1\", Key: \"key1\"")) | ||
} | ||
|
||
func Test_ValidateConfigMapDestinationAndExpressions_CollisionBetweenEachFailsValidation(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*genruntime.ConfigMapDestination{ | ||
{Name: "n3", Key: "key1"}, | ||
{Name: "n4", Key: "key1"}, | ||
{Name: "n5", Key: "key1"}, | ||
} | ||
|
||
destinationExpressions := []*core.DestinationExpression{ | ||
{Name: "n1", Key: "key1", Value: "resource.status.id"}, | ||
{Name: "n2", Key: "key1", Value: "resource.status.id"}, | ||
{Name: "n3", Key: "key1", Value: "resource.status.id"}, | ||
} | ||
|
||
_, err := configmaps.ValidateDestinationsExt(destinations, destinationExpressions) | ||
g.Expect(err).ToNot(BeNil()) | ||
g.Expect(err.Error()).To(Equal("cannot write more than one configmap value to destination Name: \"n3\", Key: \"key1\", Value: \"resource.status.id\"")) | ||
} | ||
|
||
func Test_ValidateConfigMapDestinationExpressions_EmptyKeyIgnored(t *testing.T) { | ||
t.Parallel() | ||
g := NewGomegaWithT(t) | ||
|
||
destinations := []*core.DestinationExpression{ | ||
{Name: "n1", Value: "resource.status.id"}, | ||
{Name: "n1", Key: "key1", Value: "resource.status.id"}, | ||
} | ||
|
||
warnings, err := configmaps.ValidateDestinationsExt(nil, destinations) | ||
g.Expect(warnings).To(BeNil()) | ||
g.Expect(err).To(BeNil()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package core | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// DestinationExpression is a CEL expression and a destination to store the result in. The destination may | ||
// be a secret or a configmap. The value of the expression is stored at the specified location in | ||
// the destination. | ||
// +kubebuilder:object:generate=true | ||
type DestinationExpression struct { | ||
// Name is the name of the Kubernetes configmap or secret to write to. | ||
// The configmap or secret will be created in the same namespace as the resource. | ||
// +kubebuilder:validation:Required | ||
Name string `json:"name,omitempty"` | ||
|
||
// Key is the key in the ConfigMap or Secret being written to. If the CEL expression in Value returns a string | ||
// this is required to identify what key to write to. If the CEL expression in Value returns a map[string]string | ||
// Key must not be set, instead the keys written will be determined dynamically based on the keys of the resulting | ||
// map[string]string. | ||
Key string `json:"key,omitempty"` | ||
|
||
// Value is a CEL expression. The CEL expression may return a string or a map[string]string. For more information see TODO (improve this) | ||
// +kubebuilder:validation:Required | ||
Value string `json:"value,omitempty"` | ||
} | ||
|
||
func (s DestinationExpression) String() string { | ||
return fmt.Sprintf("Name: %q, Key: %q, Value: %q", s.Name, s.Key, s.Value) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package secrets | ||
|
||
import ( | ||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/core" | ||
) | ||
|
||
// Exporter defines an interface for exporting Secrets based on CEL expressions. | ||
type Exporter interface { | ||
SecretDestinationExpressions() []*core.DestinationExpression | ||
} |
Oops, something went wrong.