forked from gardener/landscaper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve secret references in targets in deployer lib (gardener#629)
* add resolver interface and secret resolver implementation * change deployer definition to use resolved targets instead * refactor target types into own package * fix kubeconfig loading for helm and manifest deployers * add check for different namespace * make target available in container * fix tests * fix kubeconfig decoding * fix integration tests * increase timeouts for integration tests (run-int-tests) * fix target mount in container deployer * move ResolvedTarget definition to apis and make Target.Spec.Configuration a pointer (run-int-tests) * add documentation for container deployitems and targets * validate targets * use LocalSecretReference instead of SecretReference for Targets * fix nil pointer * rebase fix * fix webhook integration test (run-int-tests) * copy target to shared volume instead of mounting * add integration tests for target propagation in container deployitems * improve docs
- Loading branch information
1 parent
599edb2
commit 49fa8d3
Showing
81 changed files
with
1,901 additions
and
951 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
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,94 @@ | ||
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Gardener contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package targettypes | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"k8s.io/utils/pointer" | ||
|
||
"github.com/gardener/landscaper/apis/core" | ||
"github.com/gardener/landscaper/apis/core/v1alpha1" | ||
) | ||
|
||
// KubernetesClusterTargetType defines the landscaper kubernetes cluster target. | ||
const KubernetesClusterTargetType v1alpha1.TargetType = core.GroupName + "/kubernetes-cluster" | ||
|
||
// KubernetesClusterTargetConfig defines the landscaper kubernetes cluster target config. | ||
type KubernetesClusterTargetConfig struct { | ||
// Kubeconfig defines kubeconfig as string. | ||
Kubeconfig ValueRef `json:"kubeconfig"` | ||
} | ||
|
||
// DefaultKubeconfigKey is the default that is used to hold a kubeconfig. | ||
const DefaultKubeconfigKey = "kubeconfig" | ||
|
||
// ValueRef holds a value that can be either defined by string or by a secret ref. | ||
type ValueRef struct { | ||
StrVal *string `json:"-"` | ||
|
||
// deprecated | ||
SecretRef *v1alpha1.SecretReference `json:"secretRef,omitempty"` | ||
} | ||
|
||
// kubeconfigJSON is a helper struct for decoding. | ||
type kubeconfigJSON struct { | ||
Kubeconfig *ValueRef `json:"kubeconfig"` | ||
} | ||
|
||
// valueRefJSON is a helper struct to decode json into a secret ref object. | ||
type valueRefJSON struct { | ||
SecretRef *v1alpha1.SecretReference `json:"secretRef,omitempty"` | ||
} | ||
|
||
// MarshalJSON implements the json marshaling for a JSON | ||
func (v ValueRef) MarshalJSON() ([]byte, error) { | ||
if v.StrVal != nil { | ||
return json.Marshal(v.StrVal) | ||
} | ||
ref := valueRefJSON{ | ||
SecretRef: v.SecretRef, | ||
} | ||
return json.Marshal(ref) | ||
} | ||
|
||
// UnmarshalJSON implements json unmarshaling for a JSON | ||
func (v *ValueRef) UnmarshalJSON(data []byte) error { | ||
ref := &valueRefJSON{} | ||
err := json.Unmarshal(data, ref) | ||
if err == nil && ref.SecretRef != nil { | ||
// parsing into secret reference was successful | ||
v.SecretRef = ref.SecretRef | ||
return nil | ||
} | ||
// parse into string instead | ||
var strVal string | ||
err = json.Unmarshal(data, &strVal) | ||
if err == nil { | ||
v.StrVal = &strVal | ||
return nil | ||
} | ||
v.StrVal = pointer.String(string(data)) | ||
return nil | ||
} | ||
|
||
func (kc *KubernetesClusterTargetConfig) UnmarshalJSON(data []byte) error { | ||
kj := &kubeconfigJSON{} | ||
err := json.Unmarshal(data, kj) | ||
if err == nil && kj.Kubeconfig != nil { | ||
// parsing was successful | ||
kc.Kubeconfig = *kj.Kubeconfig | ||
return nil | ||
} | ||
return kc.Kubeconfig.UnmarshalJSON(data) | ||
} | ||
|
||
func (v ValueRef) OpenAPISchemaType() []string { | ||
return []string{ | ||
"object", | ||
"string", | ||
} | ||
} | ||
func (v ValueRef) OpenAPISchemaFormat() string { return "" } |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.