Skip to content

Commit

Permalink
add shootAnnotations to flavors
Browse files Browse the repository at this point in the history
  • Loading branch information
dguendisch committed Jul 2, 2020
1 parent 1c73b22 commit 132105b
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

package common

import (
"fmt"
"strings"
)

// Annotations
const (
// AnnotationResumeTestrun is the annotation name to trigger resume on the testrun
Expand Down Expand Up @@ -72,6 +77,9 @@ const (
// AnnotationAllowPrivilegedContainers is the annotation describing whether and how created shoots will have allowPrivilegedContainers configured
AnnotationAllowPrivilegedContainers = "metadata.testmachinery.gardener.cloud/allow-privileged-containers"

// AnnotationShootAnnotations is the annotation describing which additional shoot annotations were set (as they could impact the shoot behaviour)
AnnotationShootAnnotations = "metadata.testmachinery.gardener.cloud/shoot-annotations"

// AnnotationFlavorDescription is the annotation to describe the test flavor of the current run testrun
AnnotationFlavorDescription = "metadata.testmachinery.gardener.cloud/flavor-description"

Expand Down Expand Up @@ -115,3 +123,11 @@ var (
// Default timeout of 4 hours to wait before resuming the testrun
DefaultPauseTimeout = 14400
)

func MarshalMap(annotations map[string]string) string {
var buf []string
for k, v := range annotations {
buf = append(buf, fmt.Sprintf("%s=%s", k, v))
}
return strings.Join(buf, ",")
}
7 changes: 7 additions & 0 deletions pkg/common/types_shootflavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type Shoot struct {
// AllowPrivilegedContainers defines whether privileged containers will be allowed in the given shoot or not
AllowPrivilegedContainers *bool

// AdditionalAnnotations holds annotations to be added to created shoots
AdditionalAnnotations map[string]string

// Worker pools to test
Workers []gardencorev1beta1.Worker
}
Expand All @@ -70,6 +73,10 @@ type ShootFlavor struct {
// +optional
AllowPrivilegedContainers *bool `json:"allowPrivilegedContainers"`

// ShootAnnotations allows to optionally define additional annotations for the created shoot resources
// +optional
ShootAnnotations map[string]string `json:"shootAnnotations"`

// Worker pools to test
Workers []ShootWorkerFlavor `json:"workers"`
}
Expand Down
1 change: 1 addition & 0 deletions pkg/shootflavors/extendedflavors.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func NewExtended(k8sClient client.Client, rawFlavors []*common.ExtendedShootFlav
shoot: &common.ExtendedShoot{
Shoot: common.Shoot{
Description: rawFlavor.Description,
AdditionalAnnotations: rawFlavor.ShootAnnotations,
Provider: rawFlavor.Provider,
KubernetesVersion: k8sVersion,
AllowPrivilegedContainers: rawFlavor.AllowPrivilegedContainers,
Expand Down
2 changes: 2 additions & 0 deletions pkg/shootflavors/extendedflavors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var _ = Describe("extended flavor test", func() {
ExtendedConfiguration: defaultExtendedCfg,
ShootFlavor: common.ShootFlavor{
AllowPrivilegedContainers: pointer.BoolPtr(true),
ShootAnnotations: map[string]string{"a": "b"},
Provider: common.CloudProviderGCP,
KubernetesVersions: common.ShootKubernetesVersionFlavor{
Versions: &[]gardencorev1beta1.ExpirableVersion{
Expand All @@ -111,6 +112,7 @@ var _ = Describe("extended flavor test", func() {
Expect(shoot.Get().Shoot).To(Equal(common.Shoot{
Provider: common.CloudProviderGCP,
AllowPrivilegedContainers: pointer.BoolPtr(true),
AdditionalAnnotations: map[string]string{"a": "b"},
KubernetesVersion: gardencorev1beta1.ExpirableVersion{Version: "1.15"},
Workers: []gardencorev1beta1.Worker{{Name: "wp1"}},
}))
Expand Down
2 changes: 2 additions & 0 deletions pkg/shootflavors/flavors.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func New(rawFlavors []*common.ShootFlavor) (*Flavors, error) {
}

shoots = append(shoots, &common.Shoot{
AdditionalAnnotations: rawFlavor.ShootAnnotations,
Provider: rawFlavor.Provider,
KubernetesVersion: k8sVersion,
AllowPrivilegedContainers: rawFlavor.AllowPrivilegedContainers,
Expand All @@ -91,6 +92,7 @@ func New(rawFlavors []*common.ShootFlavor) (*Flavors, error) {
continue
}
shoots = append(shoots, &common.Shoot{
AdditionalAnnotations: rawFlavor.ShootAnnotations,
Provider: rawFlavor.Provider,
KubernetesVersion: k8sVersion,
AllowPrivilegedContainers: rawFlavor.AllowPrivilegedContainers,
Expand Down
26 changes: 26 additions & 0 deletions pkg/shootflavors/flavors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,32 @@ var _ = Describe("flavor test", func() {
))
})

It("should return one shoot with additional annotations", func() {
rawFlavors := []*common.ShootFlavor{
{
Provider: common.CloudProviderGCP,
ShootAnnotations: map[string]string{"x": "y"},
KubernetesVersions: common.ShootKubernetesVersionFlavor{
Versions: &[]gardencorev1beta1.ExpirableVersion{
{
Version: "1.15",
},
},
},
},
}
flavors, err := New(rawFlavors)
Expect(err).ToNot(HaveOccurred())
Expect(flavors.GetShoots()).To(HaveLen(1))
Expect(flavors.GetShoots()).To(ConsistOf(
&common.Shoot{
Provider: common.CloudProviderGCP,
AdditionalAnnotations: map[string]string{"x": "y"},
KubernetesVersion: gardencorev1beta1.ExpirableVersion{Version: "1.15"},
},
))
})

It("should return one shoot with disabled allowPrivilegeContainers", func() {
rawFlavors := []*common.ShootFlavor{
{
Expand Down
2 changes: 2 additions & 0 deletions pkg/testmachinery/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (m *Metadata) CreateAnnotations() map[string]string {
common.AnnotationFlavorDescription: m.FlavorDescription,
common.AnnotationDimension: m.GetDimensionFromMetadata("/"),
common.AnnotationRetries: strconv.Itoa(m.Retries),
common.AnnotationShootAnnotations: common.MarshalMap(m.Annotations),
}
if m.AllowPrivilegedContainers != nil {
annotations[common.AnnotationAllowPrivilegedContainers] = strconv.FormatBool(*m.AllowPrivilegedContainers)
Expand Down Expand Up @@ -72,6 +73,7 @@ func FromTestrun(tr *tmv1beta1.Testrun) *Metadata {
Region: tr.Annotations[common.AnnotationRegion],
Zone: tr.Annotations[common.AnnotationZone],
FlavorDescription: tr.Annotations[common.AnnotationFlavorDescription],
ShootAnnotations: tr.Annotations[common.AnnotationShootAnnotations],
Retries: retries,
Testrun: TestrunMetadata{
ID: tr.Name,
Expand Down
1 change: 1 addition & 0 deletions pkg/testmachinery/metadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Metadata struct {
OperatingSystemVersion string `json:"operating_system_version,omitempty"`
Zone string `json:"zone,omitempty"`
AllowPrivilegedContainers *bool `json:"allow_privileged_containers,omitempty"`
ShootAnnotations string `json:"shoot_annotations,omitempty"`

// ComponentDescriptor describes the current component_descriptor of the direct landscape-setup components.
// It is formatted as an array of components: { name: "my_component", version: "0.0.1" }
Expand Down
2 changes: 2 additions & 0 deletions pkg/testrun_renderer/default/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func Render(cfg *Config) (*v1beta1.Testrun, error) {
Namespace: cfg.Shoots.Namespace,
K8sVersion: flavor.KubernetesVersion.Version,
AllowPrivilegedContainers: flavor.AllowPrivilegedContainers,
ShootAnnotations: flavor.AdditionalAnnotations,
},
})
for _, test := range cfg.Shoots.Tests {
Expand All @@ -120,6 +121,7 @@ func Render(cfg *Config) (*v1beta1.Testrun, error) {
Namespace: cfg.Shoots.Namespace,
K8sVersion: flavor.KubernetesVersion.Version,
AllowPrivilegedContainers: flavor.AllowPrivilegedContainers,
ShootAnnotations: flavor.AdditionalAnnotations,
},
})
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/testrun_renderer/templates/shoots.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
ConfigInfrastructureProviderPathName = "INFRASTRUCTURE_PROVIDER_CONFIG_FILEPATH"

ConfigShootName = "SHOOT_NAME"
ConfigShootAnnotations = "SHOOT_ANNOTATIONS"
ConfigProjectNamespaceName = "PROJECT_NAMESPACE"
ConfigK8sVersionName = "K8S_VERSION"
ConfigCloudproviderName = "CLOUDPROVIDER"
Expand All @@ -49,6 +50,7 @@ var (
// CreateShootConfig describes the configuration for a create-shoot step
type CreateShootConfig struct {
ShootName string
ShootAnnotations map[string]string
Namespace string
K8sVersion string
AllowPrivilegedContainers *bool
Expand Down
5 changes: 5 additions & 0 deletions pkg/testrun_renderer/templates/shoots_v1beta1.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func defaultShootConfig(cfg *CreateShootConfig) []v1beta1.ConfigElement {
Name: ConfigSeedName,
Value: ConfigSeedValue,
},
{
Type: v1beta1.ConfigTypeEnv,
Name: ConfigShootAnnotations,
Value: common.MarshalMap(cfg.ShootAnnotations),
},
}

if cfg.AllowPrivilegedContainers != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/testrunner/template/shoot_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var _ = Describe("shoot templates", func() {
KubernetesVersion: gardencorev1beta1.ExpirableVersion{Version: "1.15.2"},
Workers: []gardencorev1beta1.Worker{{Name: "wp1", Machine: gardencorev1beta1.Machine{Image: &gardencorev1beta1.ShootMachineImage{Name: "core-os"}}}},
AllowPrivilegedContainers: pointer.BoolPtr(false),
AdditionalAnnotations: map[string]string{"a": "b"},
},
ExtendedShootConfiguration: common.ExtendedShootConfiguration{
Name: "test-name",
Expand Down Expand Up @@ -77,6 +78,7 @@ var _ = Describe("shoot templates", func() {
Expect(tr.Annotations).To(HaveKeyWithValue("shoot.region", "region-1"))
Expect(tr.Annotations).To(HaveKeyWithValue("shoot.zone", "region-1-1"))
Expect(tr.Annotations).To(HaveKeyWithValue("shoot.allowPrivilegedContainers", "false"))
Expect(tr.Annotations).To(HaveKeyWithValue("shoot.shootAnnotations", "a=b"))
Expect(tr.Annotations).To(HaveKeyWithValue("shoot.k8sVersion", "1.15.2"))
Expect(tr.Annotations).To(HaveKeyWithValue("shoot.k8sPrevPrePatchVersion", "1.15.2"))
Expect(tr.Annotations).To(HaveKeyWithValue("shoot.k8sPrevPatchVersion", "1.15.2"))
Expand All @@ -101,6 +103,7 @@ var _ = Describe("shoot templates", func() {
Expect(meta.Region).To(Equal("region-1"))
Expect(meta.Zone).To(Equal("region-1-1"))
Expect(meta.AllowPrivilegedContainers).To(Equal(pointer.BoolPtr(false)))
Expect(meta.Annotations).To(Equal(map[string]string{"a": "b"}))
Expect(meta.OperatingSystem).To(Equal("core-os"))
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ metadata:
{{- if hasKey .Values.shoot "allowPrivilegedContainers" }}
shoot.allowPrivilegedContainers: "{{ .Values.shoot.allowPrivilegedContainers }}"
{{- end }}
{{- if hasKey .Values.shoot "shootAnnotations" }}
shoot.shootAnnotations: "{{ .Values.shoot.shootAnnotations }}"
{{- end }}
shoot.workers: {{ required "workers is required" .Values.shoot.workers }}
shoot.k8sVersion: {{ required "k8sVersion is required" .Values.shoot.k8sVersion }}
shoot.k8sPrevPrePatchVersion: {{ required "k8sPrevPrePatchVersion is required" .Values.shoot.k8sPrevPrePatchVersion }}
Expand Down
4 changes: 4 additions & 0 deletions pkg/testrunner/template/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (r *shootValueRenderer) GetValues(shoot *common.ExtendedShoot, defaultValue
if shoot.AllowPrivilegedContainers != nil {
values["shoot"].(map[string]interface{})["allowPrivilegedContainers"] = shoot.AllowPrivilegedContainers
}
if shoot.AdditionalAnnotations != nil {
values["shoot"].(map[string]interface{})["shootAnnotations"] = common.MarshalMap(shoot.AdditionalAnnotations)
}
return utils.MergeMaps(defaultValues, values), nil
}

Expand All @@ -172,5 +175,6 @@ func (r *shootValueRenderer) GetMetadata(shoot *common.ExtendedShoot) (*metadata
AllowPrivilegedContainers: shoot.AllowPrivilegedContainers,
OperatingSystem: shoot.Workers[0].Machine.Image.Name, // todo: check if there a possible multiple workerpools with different images
OperatingSystemVersion: operatingsystemversion,
Annotations: shoot.AdditionalAnnotations,
}, nil
}

0 comments on commit 132105b

Please sign in to comment.