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

feat/generic-secret #221

Merged
merged 13 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
bundle/** linguist-generated=true
bundle.Dockerfile linguist-generated=true
config/crd/bases/** linguist-generated=true
docs/api-reference/reference.asciidoc linguist-generated=true
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# To re-generate a bundle for another specific version without changing the standard setup, you can:
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.13.0-alpha.1
VERSION ?= 0.13.0-alpha.2

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down Expand Up @@ -231,7 +231,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(ENVTEST) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
test -s $(ENVTEST) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.17

.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary
Expand Down
4 changes: 2 additions & 2 deletions apis/marin3r/v1alpha1/envoyconfig_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (r *EnvoyConfig) ValidateResources() error {
switch res.Type {

case envoy.Secret:
if res.GenerateFromTlsSecret == nil {
errList = append(errList, fmt.Errorf("'generateFromTlsSecret' cannot be empty for type '%s'", envoy.Secret))
if res.GenerateFromTlsSecret == nil && res.GenerateFromOpaqueSecret == nil {
errList = append(errList, fmt.Errorf("one of 'generateFromTlsSecret', 'generateFromOpaqueSecret' must be set for type '%s'", envoy.Secret))
}
if res.Value != nil {
errList = append(errList, fmt.Errorf("'value' cannot be used for type '%s'", envoy.Secret))
Expand Down
26 changes: 26 additions & 0 deletions apis/marin3r/v1alpha1/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ type Resource struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
GenerateFromTlsSecret *string `json:"generateFromTlsSecret,omitempty"`
// The name of a Kubernetes Secret of type "Opaque". It will generate an
// envoy "generic secret" proto.
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +optional
GenerateFromOpaqueSecret *SecretKeySelector `json:"generateFromOpaqueSecret,omitempty"`
// Specifies a label selector to watch for EndpointSlices that will
// be used to generate the endpoint resource
// +operator-sdk:csv:customresourcedefinitions:type=spec
Expand All @@ -63,6 +68,27 @@ func (r *Resource) GetBlueprint() Blueprint {
return defaultBlueprint
}

func (r *Resource) SecretRef() (string, error) {
if r.Type != envoy.Secret {
return "", fmt.Errorf("not a secret type")
}
if r.GenerateFromOpaqueSecret != nil {
return r.GenerateFromOpaqueSecret.Name, nil
} else if r.GenerateFromTlsSecret != nil {
return *r.GenerateFromTlsSecret, nil
}
return "", fmt.Errorf("secret reference not set")
}

type SecretKeySelector struct {
// The name of the secret in the pod's namespace to select from.
Name string `json:"name"`
// The key of the secret to select from. Must be a valid secret key.
Key string `json:"key"`
// A unique name to refer to the name:key combination
Alias string `json:"alias"`
}

type GenerateFromEndpointSlices struct {
Selector *metav1.LabelSelector `json:"selector"`
ClusterName string `json:"clusterName"`
Expand Down
20 changes: 20 additions & 0 deletions apis/marin3r/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions bundle/manifests/marin3r.3scale.net_envoyconfigrevisions.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions bundle/manifests/marin3r.3scale.net_envoyconfigs.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions bundle/manifests/marin3r.clusterserviceversion.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions config/crd/bases/marin3r.3scale.net_envoyconfigrevisions.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions config/crd/bases/marin3r.3scale.net_envoyconfigs.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/3scale/marin3r
newTag: v0.13.0-alpha.1
newTag: v0.13.0-alpha.2

patchesStrategicMerge:
- custom/manager_patch.yaml
8 changes: 8 additions & 0 deletions config/manifests/bases/marin3r.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ spec:
be used to generate the endpoint resource
displayName: Generate From Endpoint Slices
path: resources[0].generateFromEndpointSlices
- description: The name of a Kubernetes Secret of type "Opaque". It will generate
an envoy "generic secret" proto.
displayName: Generate From Opaque Secret
path: resources[0].generateFromOpaqueSecret
- description: The name of a Kubernetes Secret of type "kubernetes.io/tls"
displayName: Generate From Tls Secret
path: resources[0].generateFromTlsSecret
Expand Down Expand Up @@ -541,6 +545,10 @@ spec:
be used to generate the endpoint resource
displayName: Generate From Endpoint Slices
path: resources[0].generateFromEndpointSlices
- description: The name of a Kubernetes Secret of type "Opaque". It will generate
an envoy "generic secret" proto.
displayName: Generate From Opaque Secret
path: resources[0].generateFromOpaqueSecret
- description: The name of a Kubernetes Secret of type "kubernetes.io/tls"
displayName: Generate From Tls Secret
path: resources[0].generateFromTlsSecret
Expand Down
2 changes: 1 addition & 1 deletion config/webhook/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/3scale/marin3r
newTag: v0.13.0-alpha.1
newTag: v0.13.0-alpha.2

# [CUSTOM: pod mutating webhook config] This patch adds a label selector to the MutatingWebhookConfig
patchesStrategicMerge:
Expand Down
5 changes: 3 additions & 2 deletions controllers/marin3r/envoyconfigrevision_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,16 @@ func (r *EnvoyConfigRevisionReconciler) SecretsEventHandler() handler.EventHandl
&marin3rv1alpha1.EnvoyConfigRevisionList{},
func(event client.Object, o client.Object) bool {
secret := event.(*corev1.Secret)
if secret.Type != corev1.SecretTypeTLS {
if secret.Type != corev1.SecretTypeTLS && secret.Type != corev1.SecretTypeOpaque {
return false
}
ecr := o.(*marin3rv1alpha1.EnvoyConfigRevision)
if meta.IsStatusConditionTrue(ecr.Status.Conditions, marin3rv1alpha1.RevisionPublishedCondition) {
// check if the k8s Secret is relevant for this EnvoyConfigRevision
for _, s := range ecr.Spec.Resources {
if s.Type == envoy.Secret {
if *s.GenerateFromTlsSecret == secret.GetName() {
if (s.GenerateFromTlsSecret != nil && *s.GenerateFromTlsSecret == secret.GetName()) ||
(s.GenerateFromOpaqueSecret != nil && s.GenerateFromOpaqueSecret.Name == secret.GetName()) {
return true
}
}
Expand Down
20 changes: 20 additions & 0 deletions docs/api-reference/reference.asciidoc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading