Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from danielfoehrKn/harmoninze-blueprint
Browse files Browse the repository at this point in the history
Harmoninze blueprint
  • Loading branch information
danielfoehrKn authored Feb 7, 2022
2 parents be75411 + e700123 commit 351df3f
Show file tree
Hide file tree
Showing 27 changed files with 142 additions and 116 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
/.kube-secrets
/tmp/*
/local
/gen
**/dev

*.coverprofile
*.html
.vscode
.cache_ggshield
.idea
.DS_Store
*~
13 changes: 9 additions & 4 deletions .landscaper/blueprint/blueprint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ apiVersion: landscaper.gardener.cloud/v1alpha1
kind: Blueprint

imports:
- name: cluster
- name: runtimeCluster
required: true
targetType: landscaper.gardener.cloud/kubernetes-cluster

- name: hostingCluster
- name: runtimeClusterSettings
schema:
type: object
properties:
Expand Down Expand Up @@ -242,7 +242,7 @@ imports:
type: string

exports:
- name: kubeApiserverCaPem
- name: virtualGardenApiserverCaPem
schema:
type: string

Expand All @@ -262,7 +262,12 @@ exports:
schema:
type: string

- name: virtualGardenKubeconfig
- name: etcdUrl
schema:
type: string

- name: virtualGardenCluster
type: target
targetType: landscaper.gardener.cloud/kubernetes-cluster

- name: virtualGardenEndpoint
Expand Down
4 changes: 2 additions & 2 deletions .landscaper/blueprint/virtual-garden-deploy-execution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ deployItems:
- name: virtual-garden-container-deployer
type: landscaper.gardener.cloud/container
target:
name: {{ index .imports "cluster" "metadata" "name" }}
namespace: {{ index .imports "cluster" "metadata" "namespace" }}
name: {{ index .imports "runtimeCluster" "metadata" "name" }}
namespace: {{ index .imports "runtimeCluster" "metadata" "namespace" }}
config:
apiVersion: container.deployer.landscaper.gardener.cloud/v1alpha1
kind: ProviderConfiguration
Expand Down
9 changes: 6 additions & 3 deletions .landscaper/blueprint/virtual-garden-export-execution.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exports:
kubeApiserverCaPem: |
{{- index .values "deployitems" "virtual-garden-container-deployer" "kubeApiserverCaPem" | nindent 4 }}
virtualGardenApiserverCaPem: |
{{- index .values "deployitems" "virtual-garden-container-deployer" "virtualGardenApiserverCaPem" | nindent 4 }}
etcdCaPem: |
{{- index .values "deployitems" "virtual-garden-container-deployer" "etcdCaPem" | nindent 4 }}
Expand All @@ -11,10 +11,13 @@ exports:
etcdClientTlsKeyPem: |
{{- index .values "deployitems" "virtual-garden-container-deployer" "etcdClientTlsKeyPem" | nindent 4 }}
etcdUrl: |
{{- index .values "deployitems" "virtual-garden-container-deployer" "etcdUrl" | nindent 4 }}
virtualGardenEndpoint: |
{{- index .values "deployitems" "virtual-garden-container-deployer" "virtualGardenEndpoint" | nindent 4 }}
virtualGardenKubeconfig:
virtualGardenCluster:
type: landscaper.gardener.cloud/kubernetes-cluster
config:
kubeconfig: |
Expand Down
4 changes: 2 additions & 2 deletions cmd/virtual-garden/app/virtual_garden.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ func run(ctx context.Context, log *logrus.Logger, opts *Options) error {
}

log.Infof("Creating REST config and Kubernetes client based on given kubeconfig")
client, err := NewClientFromTarget(imports.Cluster)
client, err := NewClientFromTarget(imports.RuntimeCluster)
if err != nil {
return err
}

operation, err := virtualgarden.NewOperation(client, log, imports.HostingCluster.Namespace, imports, imageRefs)
operation, err := virtualgarden.NewOperation(client, log, imports.RuntimeClusterSettings.Namespace, imports, imageRefs)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion docs/deploy-virtual-garden-with-landscaper.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The component descriptor contains the list of all resources required for the dep

- the blueprint,
- the image from the previous step, which will be executed by the container deployer,
- the images of etcd, kube-apiserver, etc. which will be deployed to the host cluster of the virtual garden.
- the images of etcd, kube-apiserver, etc. which will be deployed to the runtime cluster of the virtual garden.

### Creating a Target and an Installation

Expand Down
4 changes: 2 additions & 2 deletions example/imports.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cluster:
runtimeCluster:
apiVersion: landscaper.gardener.cloud/v1alpha1
kind: Target
spec:
Expand All @@ -7,7 +7,7 @@ cluster:
kubeconfig: |
# ... <please insert your kubeconfig here>

hostingCluster:
runtimeClusterSettings:
namespace: garden
infrastructureProvider: gcp

Expand Down
27 changes: 15 additions & 12 deletions hack/create-installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ spec:
imports:
targets:
- name: cluster
target: "#cluster"
- name: runtimeCluster
target: "#runtime-cluster"
# static data to not require to import config map
importDataMappings:
hostingCluster:
runtimeClusterSettings:
namespace: garden
infrastructureProvider: gcp
infrastructureProvider: aws
virtualGarden:
deleteNamespace: true
Expand All @@ -62,20 +63,22 @@ spec:
exports:
data:
- name: kubeApiserverCaPem
dataRef: "kubeapiservercapem"
- name: virtualGardenApiserverCaPem
dataRef: "virtual-garden-apiserver-ca-pem"
- name: etcdCaPem
dataRef: "etcdcapem"
dataRef: "etcd-ca-pem"
- name: etcdClientTlsPem
dataRef: "etcdclienttlspem"
dataRef: "etcd-client-tls-pem"
- name: etcdClientTlsKeyPem
dataRef: "etcdclienttlskeypem"
dataRef: "etcd-client-tls-key-pem"
- name: virtualGardenEndpoint
dataRef: "virtualgardenendpoint"
dataRef: "virtual-garden-endpoint"
- name: etcdUrl
dataRef: "etcd-url"
targets:
- name: virtualGardenKubeconfig
target: "virtualgardenkubeconfig"
- name: virtualGardenCluster
target: "virtual-garden-cluster"
EOF

echo "Installation stored at ${INSTALLATION_PATH}"
7 changes: 6 additions & 1 deletion hack/generate-cd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ component-cli ca create "${CA_PATH}" \

echo "> Extending resources.yaml: adding image of virtual-garden deployer"
RESOURCES_BASE_PATH="$(mktemp -d)"
cp -R ".landscaper/" "${RESOURCES_BASE_PATH}"

# using .landscaper/resources yaml containing the blueprint and the required OCI images
cp -a ".landscaper/." "${RESOURCES_BASE_PATH}"

RESOURCES_FILE_PATH="${RESOURCES_BASE_PATH}/resources.yaml"

cat << EOF >> ${RESOURCES_FILE_PATH}
---
type: ociImage
Expand All @@ -67,3 +70,5 @@ mkdir -p ./gen
CTF_PATH=${CTF_PATH} BASE_DEFINITION_PATH=${BASE_DEFINITION_PATH} CURRENT_COMPONENT_REPOSITORY=${REPO_CTX} RESOURCES_FILE_PATH=${RESOURCES_FILE_PATH} bash $SOURCE_PATH/.ci/component_descriptor

component-cli ctf push --repo-ctx=${REPO_CTX} "${CTF_PATH}"

echo "View the component descriptor with: component-cli component-archive remote get ${REPO_CTX} github.com/gardener/virtual-garden ${EFFECTIVE_VERSION}"
17 changes: 9 additions & 8 deletions pkg/api/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@

package api

// Eports defines the structure for the exported data which might be consumed by other components.
// Exports defines the structure for the exported data which might be consumed by other components.
type Exports struct {
KubeApiserverCaPem string `json:"kubeApiserverCaPem,omitempty" yaml:"kubeApiserverCaPem,omitempty"`
ServiceAccountKeyPem string `json:"serviceAccountKeyPem,omitempty" yaml:"serviceAccountKeyPem,omitempty"`
EtcdCaPem string `json:"etcdCaPem,omitempty" yaml:"etcdCaPem,omitempty"`
EtcdClientTlsPem string `json:"etcdClientTlsPem,omitempty" yaml:"etcdClientTlsPem,omitempty"`
EtcdClientTlsKeyPem string `json:"etcdClientTlsKeyPem,omitempty" yaml:"etcdClientTlsKeyPem,omitempty"`
KubeconfigYaml string `json:"kubeconfigYaml,omitempty" yaml:"kubeconfigYaml,omitempty"`
VirtualGardenEndpoint string `json:"virtualGardenEndpoint,omitempty" yaml:"virtualGardenEndpoint,omitempty"`
VirtualGardenApiserverCaPem string `json:"virtualGardenApiserverCaPem,omitempty" yaml:"virtualGardenApiserverCaPem,omitempty"`
ServiceAccountKeyPem string `json:"serviceAccountKeyPem,omitempty" yaml:"serviceAccountKeyPem,omitempty"`
EtcdCaPem string `json:"etcdCaPem,omitempty" yaml:"etcdCaPem,omitempty"`
EtcdClientTlsPem string `json:"etcdClientTlsPem,omitempty" yaml:"etcdClientTlsPem,omitempty"`
EtcdClientTlsKeyPem string `json:"etcdClientTlsKeyPem,omitempty" yaml:"etcdClientTlsKeyPem,omitempty"`
EtcdUrl string `json:"etcdUrl,omitempty" yaml:"etcdUrl,omitempty"`
KubeconfigYaml string `json:"kubeconfigYaml,omitempty" yaml:"kubeconfigYaml,omitempty"`
VirtualGardenEndpoint string `json:"virtualGardenEndpoint,omitempty" yaml:"virtualGardenEndpoint,omitempty"`
}
12 changes: 6 additions & 6 deletions pkg/api/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ const (

// Imports defines the structure for the required configuration values from other components.
type Imports struct {
// Cluster is the kubeconfig of the hosting cluster into which the virtual garden shall be installed.
Cluster lsv1alpha1.Target `json:"cluster" yaml:"cluster"`
// HostingCluster contains settings for the hosting cluster that runs the virtual garden.
HostingCluster HostingCluster `json:"hostingCluster" yaml:"hostingCluster"`
// RuntimeCluster is the kubeconfig of the cluster into which the virtual garden shall be installed.
RuntimeCluster lsv1alpha1.Target `json:"runtimeCluster" yaml:"runtimeCluster"`
// RuntimeClusterSettings contains settings for the hosting cluster that runs the virtual garden.
RuntimeClusterSettings ClusterSettings `json:"runtimeClusterSettings" yaml:"runtimeClusterSettings"`
// VirtualGarden contains configuration for the virtual garden cluster.
VirtualGarden VirtualGarden `json:"virtualGarden" yaml:"virtualGarden"`
}

// HostingCluster contains settings for the hosting cluster that runs the virtual garden.
type HostingCluster struct {
// ClusterSettings contains settings for the hosting cluster that runs the virtual garden.
type ClusterSettings struct {
// Namespace is a namespace in the hosting cluster into which the virtual garden shall be installed.
Namespace string `json:"namespace" yaml:"namespace"`
// InfrastructureProvider is the provider type of the underlying infrastructure of the hosting cluster.
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/loader/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ var _ = Describe("Exports", func() {
It("should succeed writing and reading", func() {
path := filepath.Join(dir, "imports.yaml")
exports := &api.Exports{
KubeApiserverCaPem: "KubeApiserverCaPem-string",
EtcdCaPem: "EtcdCaPem-string",
EtcdClientTlsPem: "EtcdClientTlsPem-string",
EtcdClientTlsKeyPem: "EtcdClientTlsKeyPem-string",
KubeconfigYaml: "KubeconfigYaml-string",
VirtualGardenEndpoint: "VirtualGardenEndpoint-string",
VirtualGardenApiserverCaPem: "VirtualGardenApiserverCaPem-string",
EtcdCaPem: "EtcdCaPem-string",
EtcdClientTlsPem: "EtcdClientTlsPem-string",
EtcdClientTlsKeyPem: "EtcdClientTlsKeyPem-string",
KubeconfigYaml: "KubeconfigYaml-string",
VirtualGardenEndpoint: "VirtualGardenEndpoint-string",
}

err := ExportsToFile(exports, path)
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/loader/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ var _ = Describe("Imports", func() {

It("should succeed reading and parsing the file (YAML)", func() {
path := filepath.Join(dir, "imports.yaml")
Expect(ioutil.WriteFile(path, []byte("virtualGarden: {}\nhostingCluster: {namespace: foo}\ncredentials: {}"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(path, []byte("virtualGarden: {}\nruntimeClusterSettings: {namespace: foo}\ncredentials: {}"), 0644)).To(Succeed())

imports, err := ImportsFromFile(path)
Expect(err).NotTo(HaveOccurred())
Expect(imports).To(Equal(&api.Imports{
HostingCluster: api.HostingCluster{Namespace: "foo"},
RuntimeClusterSettings: api.ClusterSettings{Namespace: "foo"},
}))
})

It("should succeed reading and parsing the file (JSON)", func() {
path := filepath.Join(dir, "imports.json")
Expect(ioutil.WriteFile(path, []byte(`{"virtualGarden": {}, "hostingCluster": {"namespace": "foo"}, "credentials": {}}`), 0644)).To(Succeed())
Expect(ioutil.WriteFile(path, []byte(`{"virtualGarden": {}, "runtimeClusterSettings": {"namespace": "foo"}, "credentials": {}}`), 0644)).To(Succeed())

imports, err := ImportsFromFile(path)
Expect(err).NotTo(HaveOccurred())
Expect(imports).To(Equal(&api.Imports{
HostingCluster: api.HostingCluster{Namespace: "foo"},
RuntimeClusterSettings: api.ClusterSettings{Namespace: "foo"},
}))
})
})
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/validation/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
func ValidateImports(obj *api.Imports) field.ErrorList {
allErrs := field.ErrorList{}

allErrs = append(allErrs, ValidateCluster(&obj.Cluster, field.NewPath("cluster"))...)
allErrs = append(allErrs, ValidateHostingCluster(&obj.HostingCluster, field.NewPath("hostingCluster"))...)
allErrs = append(allErrs, ValidateCluster(&obj.RuntimeCluster, field.NewPath("cluster"))...)
allErrs = append(allErrs, ValidateHostingCluster(&obj.RuntimeClusterSettings, field.NewPath("hostingCluster"))...)
allErrs = append(allErrs, ValidateVirtualGarden(&obj.VirtualGarden, field.NewPath("virtualGarden"))...)

return allErrs
Expand All @@ -55,8 +55,8 @@ func ValidateCluster(obj *lsv1alpha1.Target, fldPath *field.Path) field.ErrorLis
return allErrs
}

// ValidateHostingCluster validates a HostingCluster object.
func ValidateHostingCluster(obj *api.HostingCluster, fldPath *field.Path) field.ErrorList {
// ValidateHostingCluster validates a ClusterSettings object.
func ValidateHostingCluster(obj *api.ClusterSettings, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

if len(obj.Namespace) == 0 {
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/validation/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ var _ = Describe("Imports", func() {

BeforeEach(func() {
obj = &api.Imports{
Cluster: lsv1alpha1.Target{
RuntimeCluster: lsv1alpha1.Target{
Spec: lsv1alpha1.TargetSpec{
Configuration: lsv1alpha1.AnyJSON{
RawMessage: json.RawMessage(`{"config":{"kubeconfig":"x"}}`),
},
},
},
HostingCluster: api.HostingCluster{
RuntimeClusterSettings: api.ClusterSettings{
Namespace: "foo",
InfrastructureProvider: "gcp",
},
Expand All @@ -69,9 +69,9 @@ var _ = Describe("Imports", func() {

Context("hosting cluster", func() {
It("should fail for an invalid configuration", func() {
obj.Cluster = lsv1alpha1.Target{}
obj.HostingCluster.Namespace = ""
obj.HostingCluster.InfrastructureProvider = ""
obj.RuntimeCluster = lsv1alpha1.Target{}
obj.RuntimeClusterSettings.Namespace = ""
obj.RuntimeClusterSettings.InfrastructureProvider = ""

Expect(ValidateImports(obj)).To(ConsistOf(
PointTo(MatchFields(IgnoreExtras, Fields{
Expand Down
7 changes: 7 additions & 0 deletions pkg/virtualgarden/etcd_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package virtualgarden

import (
"context"
"fmt"

"github.com/gardener/gardener/pkg/utils"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -61,6 +62,12 @@ func (o *operation) deployETCDService(ctx context.Context, role string) error {
})
return nil
})

// export the etcd Url
if role == ETCDRoleMain {
o.exports.EtcdUrl = fmt.Sprintf("%s.%s.svc:%d", service.Name, service.Namespace, etcdServiceClientPort)
}

return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/virtualgarden/kube_api_server_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (o *operation) deployKubeApiServerApiServerCACertificate(ctx context.Contex
return nil, err
}

o.exports.KubeApiserverCaPem = string(cert.CertificatePEM)
o.exports.VirtualGardenApiserverCaPem = string(cert.CertificatePEM)

checksums[ChecksumKeyKubeAPIServerCA] = checksum
return cert, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/virtualgarden/kube_api_server_certificates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ var _ = Describe("Api Server create certificates test", func() {

func getImportsApiServerCertificatesTest() api.Imports {
return api.Imports{
Cluster: lsv1alpha1.Target{},
HostingCluster: api.HostingCluster{},
RuntimeCluster: lsv1alpha1.Target{},
RuntimeClusterSettings: api.ClusterSettings{},
VirtualGarden: api.VirtualGarden{
ETCD: nil,
KubeAPIServer: &api.KubeAPIServer{
Expand Down
4 changes: 2 additions & 2 deletions pkg/virtualgarden/kube_api_server_configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ var _ = Describe("Api Server create configmaps test", func() {

func getImportsForApiServerConfigMapsTest() api.Imports {
return api.Imports{
Cluster: lsv1alpha1.Target{},
HostingCluster: api.HostingCluster{},
RuntimeCluster: lsv1alpha1.Target{},
RuntimeClusterSettings: api.ClusterSettings{},
VirtualGarden: api.VirtualGarden{
ETCD: nil,
KubeAPIServer: &api.KubeAPIServer{
Expand Down
Loading

0 comments on commit 351df3f

Please sign in to comment.