Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/gardener/ga…
Browse files Browse the repository at this point in the history
…rdener-1.100.0
  • Loading branch information
Disper authored Jul 31, 2024
2 parents 934e065 + 626b9cc commit ca7f1a6
Showing 28 changed files with 354 additions and 42 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ FROM golang:1.22.5 as builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
WORKDIR /project_workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
@@ -27,7 +27,8 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /project_workspace/manager .
COPY converter_config.json .
USER 65532:65532

ENTRYPOINT ["/manager"]
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ func main() {
flag.DurationVar(&expirationTime, "kubeconfig-expiration-time", defaultExpirationTime, "Dynamic kubeconfig expiration time")
flag.DurationVar(&gardenerRequestTimeout, "gardener-request-timeout", defaultGardenerRequestTimeout, "Timeout duration for requests to Gardener")
flag.BoolVar(&enableRuntimeReconciler, "runtime-reconciler-enabled", defaultRuntimeReconcilerEnabled, "Feature flag for all runtime reconciler functionalities")
flag.StringVar(&converterConfigFilepath, "converter-config-filepath", "hack/converter_config.json", "A file path to the gardener shoot converter configuration.")
flag.StringVar(&converterConfigFilepath, "converter-config-filepath", "converter_config.json", "A file path to the gardener shoot converter configuration.")
flag.BoolVar(&shootSpecDumpEnabled, "shoot-spec-dump-enabled", false, "Feature flag to allow persisting specs of created shoots")

opts := zap.Options{
4 changes: 3 additions & 1 deletion config/manager/converter_config.yaml
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@ data:
converter_config_aws.json: |
{
"kubernetes": {
"defaultVersion": "1.29"
"defaultVersion": "1.29",
"enableKubernetesVersionAutoUpdate": true,
"enableMachineImageVersionAutoUpdate": false
},
"dns": {
"secretName": "aws-route53-secret-dev",
4 changes: 3 additions & 1 deletion hack/converter_config.json → converter_config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"kubernetes": {
"defaultVersion": "1.29"
"defaultVersion": "1.29",
"enableKubernetesVersionAutoUpdate": true,
"enableMachineImageVersionAutoUpdate": false
},
"dns": {
"secretName": "aws-route53-secret-dev",
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ require (
github.com/gardener/gardener-extension-provider-openstack v1.41.0
github.com/go-logr/logr v1.4.2
github.com/go-playground/validator/v10 v10.22.0
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/onsi/ginkgo/v2 v2.19.1
github.com/onsi/gomega v1.34.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/stretchr/testify v1.9.0
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -100,10 +100,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/onsi/ginkgo/v2 v2.19.1 h1:QXgq3Z8Crl5EL1WBAC98A5sEBHARrAJNzAmMxzLcRF0=
github.com/onsi/ginkgo/v2 v2.19.1/go.mod h1:O3DtEWQkPa/F7fBMgmZQKKsluAy8pd3rEQdrjkPb9zA=
github.com/onsi/gomega v1.34.0 h1:eSSPsPNp6ZpsG8X1OVmOTxig+CblTc4AxpPBykhe2Os=
github.com/onsi/gomega v1.34.0/go.mod h1:MIKI8c+f+QLWk+hxbePD4i0LMJSExPaZOVfkoex4cAo=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
23 changes: 23 additions & 0 deletions hack/shoot-comparator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.22.5-alpine AS build
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workdir

COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download

COPY cmd/ cmd/
COPY internal/ internal/
COPY pkg/ pkg/

ARG BIN
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o shoot-comparator cmd/main.go

FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=build /workdir/shoot-comparator .
USER 65532:65532

ENTRYPOINT ["/shoot-comparator"]
4 changes: 2 additions & 2 deletions hack/shoot-comparator/README.md
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@ For more details, please refer to the following issues:

## Build
```
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ./bin/comparator ./cmd
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ./bin/shoot-comparator ./cmd
```

## Run

To compare files, execute the following command:
```
comparator files <shoot file generated by Provisioner> <shoot file generated by KIM>
shoot-comparator files <shoot file generated by Provisioner> <shoot file generated by KIM>
```
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import (

func sFnCreateShoot(ctx context.Context, m *fsm, s *systemState) (stateFn, *ctrl.Result, error) {
m.log.Info("Create shoot state")

newShoot, err := convertShoot(&s.instance, m.ConverterConfig)
if err != nil {
m.log.Error(err, "Failed to convert Runtime instance to shoot object")
3 changes: 2 additions & 1 deletion internal/controller/runtime/fsm/runtime_fsm_delete_shoot.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"context"

imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
@@ -18,7 +19,7 @@ func sFnDeleteShoot(ctx context.Context, m *fsm, s *systemState) (stateFn, *ctrl

err := m.ShootClient.Patch(ctx, s.shoot, client.Apply, &client.PatchOptions{
FieldManager: "kim",
Force: ptrTo(true),
Force: ptr.To(true),
})

if err != nil {
7 changes: 2 additions & 5 deletions internal/controller/runtime/fsm/runtime_fsm_patch_shoot.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import (
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"github.com/kyma-project/infrastructure-manager/internal/gardener/shoot"
gardener_shoot "github.com/kyma-project/infrastructure-manager/internal/gardener/shoot"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
@@ -24,7 +25,7 @@ func sFnPatchExistingShoot(ctx context.Context, m *fsm, s *systemState) (stateFn

err = m.ShootClient.Patch(ctx, &updatedShoot, client.Apply, &client.PatchOptions{
FieldManager: "kim",
Force: ptrTo(true),
Force: ptr.To(true),
})

if err != nil {
@@ -84,7 +85,3 @@ func updateStatePendingWithErrorAndStop(instance *imv1.Runtime,
instance.UpdateStatePending(c, r, "False", msg)
return updateStatusAndStop()
}

func ptrTo[T any](v T) *T {
return &v
}
23 changes: 19 additions & 4 deletions internal/controller/runtime/fsm/runtime_fsm_persist_shoot.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (
"io"
"os"

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/yaml"
)
@@ -19,7 +18,7 @@ func getWriterForFilesystem(filePath string) (io.Writer, error) {
return file, nil
}

func persist(path string, s *gardener.Shoot, saveFunc writerGetter) error {
func persist(path string, s interface{}, saveFunc writerGetter) error {
writer, err := saveFunc(path)
if err != nil {
return fmt.Errorf("unable to create file: %w", err)
@@ -37,9 +36,25 @@ func persist(path string, s *gardener.Shoot, saveFunc writerGetter) error {
}

func sFnDumpShootSpec(_ context.Context, m *fsm, s *systemState) (stateFn, *ctrl.Result, error) {
path := fmt.Sprintf("%s/%s-%s.yaml", m.PVCPath, s.shoot.Namespace, s.shoot.Name)
if err := persist(path, s.shoot, m.writerProvider); err != nil {
paths := createFilesPath(m.PVCPath, s.shoot.Namespace, s.shoot.Name)

shootCp := s.shoot.DeepCopy()
runtimeCp := s.instance.DeepCopy()
shootCp.ManagedFields = nil

if err := persist(paths["shoot"], shootCp, m.writerProvider); err != nil {
return updateStatusAndStopWithError(err)
}

if err := persist(paths["runtime"], runtimeCp, m.writerProvider); err != nil {
return updateStatusAndStopWithError(err)
}
return updateStatusAndRequeueAfter(gardenerRequeueDuration)
}

func createFilesPath(pvcPath, namespace, name string) map[string]string {
m := make(map[string]string)
m["shoot"] = fmt.Sprintf("%s/%s-%s-shootCR.yaml", pvcPath, namespace, name)
m["runtime"] = fmt.Sprintf("%s/%s-%s-runtimeCR.yaml", pvcPath, namespace, name)
return m
}
Original file line number Diff line number Diff line change
@@ -24,11 +24,13 @@ var _ = Describe("KIM sFnPersist", func() {
testCtx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

expectedData, err := yaml.Marshal(&testing.ShootNoDNS)
shootWrite, err := yaml.Marshal(&testing.ShootNoDNS)
runtimeWrite, err := yaml.Marshal(&testing.RuntimeOnlyName)
expectedData := append(shootWrite, runtimeWrite...)
Expect(err).ShouldNot(HaveOccurred())

It("should persist shoot data", func() {
next, _, err := sFnDumpShootSpec(testCtx, must(newFakeFSM, withStorageWriter(testWriterGetter)), &systemState{shoot: &testing.ShootNoDNS})
next, _, err := sFnDumpShootSpec(testCtx, must(newFakeFSM, withStorageWriter(testWriterGetter)), &systemState{shoot: &testing.ShootNoDNS, instance: testing.RuntimeOnlyName})
Expect(err).To(BeNil())
Expect(next).To(haveName("sFnUpdateStatus"))
Expect(expectedData).To(Equal(b.Bytes()))
11 changes: 11 additions & 0 deletions internal/controller/runtime/fsm/testing/shoot.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package testing

import (
gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
v1 "github.com/kyma-project/infrastructure-manager/api/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

@@ -13,6 +14,16 @@ var (
},
}

RuntimeOnlyName = v1.Runtime{
ObjectMeta: metav1.ObjectMeta{
Name: "test-instance",
Namespace: "default",
},
Spec: v1.RuntimeSpec{
Shoot: v1.RuntimeShoot{Name: "test-shoot"},
},
}

ShootNoDNSDomain = gardener.Shoot{
ObjectMeta: metav1.ObjectMeta{
Name: "test-instance",
9 changes: 3 additions & 6 deletions internal/controller/runtime/suite_test.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
clienttesting "k8s.io/client-go/testing"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -179,7 +180,7 @@ func fixShootsSequenceForProvisioning(shoot *gardener_api.Shoot) []*gardener_api
dnsShoot := initialisedShoot.DeepCopy()

dnsShoot.Spec.DNS = &gardener_api.DNS{
Domain: ptrTo("test.domain"),
Domain: ptr.To("test.domain"),
}

pendingShoot := dnsShoot.DeepCopy()
@@ -208,7 +209,7 @@ func fixShootsSequenceForUpdate(shoot *gardener_api.Shoot) []*gardener_api.Shoot
pendingShoot := shoot.DeepCopy()

pendingShoot.Spec.DNS = &gardener_api.DNS{
Domain: ptrTo("test.domain"),
Domain: ptr.To("test.domain"),
}

pendingShoot.Status = gardener_api.ShootStatus{
@@ -252,7 +253,3 @@ func fixConverterConfigForTests() gardener_shoot.ConverterConfig {
},
}
}

func ptrTo[T any](v T) *T {
return &v
}
7 changes: 6 additions & 1 deletion internal/gardener/shoot/converter.go
Original file line number Diff line number Diff line change
@@ -33,7 +33,9 @@ type DNSConfig struct {
}

type KubernetesConfig struct {
DefaultVersion string `json:"defaultVersion" validate:"required"`
DefaultVersion string `json:"defaultVersion" validate:"required"`
EnableKubernetesVersionAutoUpdate bool `json:"enableKubernetesVersionAutoUpdate"`
EnableMachineImageVersionAutoUpdate bool `json:"enableMachineImageVersionVersionAutoUpdate"`
}

type ReaderGetter = func() (io.Reader, error)
@@ -72,7 +74,10 @@ func NewConverter(config ConverterConfig) Converter {
extender.ExtendWithOIDC,
extender.ExtendWithCloudProfile,
extender.ExtendWithNetworkFilter,
extender.ExtendWithCertConfig,
extender.ExtendWithExposureClassName,
extender.ExtendWithTolerations,
extender.NewMaintenanceExtender(config.Kubernetes.EnableKubernetesVersionAutoUpdate, config.Kubernetes.EnableMachineImageVersionAutoUpdate),
}

return Converter{
12 changes: 9 additions & 3 deletions internal/gardener/shoot/converter_test.go
Original file line number Diff line number Diff line change
@@ -40,7 +40,9 @@ func TestConverter(t *testing.T) {
func fixConverterConfig() ConverterConfig {
return ConverterConfig{
Kubernetes: KubernetesConfig{
DefaultVersion: "1.29", //nolint:godox TODO: set on deployment level
DefaultVersion: "1.29",
EnableKubernetesVersionAutoUpdate: true,
EnableMachineImageVersionAutoUpdate: false,
},
DNS: DNSConfig{
SecretName: "dns-secret",
@@ -134,7 +136,9 @@ func Test_ConverterConfig_Load_Err(t *testing.T) {

var testReader io.Reader = strings.NewReader(`{
"kubernetes": {
"defaultVersion": "0.1.2.3"
"defaultVersion": "0.1.2.3",
"enableKubernetesVersionAutoUpdate": true,
"enableMachineImageVersionAutoUpdate": false
},
"dns": {
"secretName": "test-secret-name",
@@ -165,7 +169,9 @@ func Test_ConverterConfig_Load_OK(t *testing.T) {

expected := ConverterConfig{
Kubernetes: KubernetesConfig{
DefaultVersion: "0.1.2.3",
DefaultVersion: "0.1.2.3",
EnableKubernetesVersionAutoUpdate: true,
EnableMachineImageVersionAutoUpdate: false,
},
DNS: DNSConfig{
SecretName: "test-secret-name",
50 changes: 50 additions & 0 deletions internal/gardener/shoot/extender/cert_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package extender

import (
"encoding/json"

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
apimachineryRuntime "k8s.io/apimachinery/pkg/runtime"
)

func ExtendWithCertConfig(_ imv1.Runtime, shoot *gardener.Shoot) error {
certConfig := NewCertConfig()
jsonCertConfig, encodingErr := json.Marshal(certConfig)
if encodingErr != nil {
return encodingErr
}

certServiceExtension := gardener.Extension{
Type: "shoot-cert-service",
ProviderConfig: &apimachineryRuntime.RawExtension{Raw: jsonCertConfig},
}

shoot.Spec.Extensions = append(shoot.Spec.Extensions, certServiceExtension)

return nil
}

type ExtensionProviderConfig struct {
// APIVersion is gardener extension api version
APIVersion string `json:"apiVersion"`
// DnsProviderReplication indicates whether dnsProvider replication is on
DNSProviderReplication *DNSProviderReplication `json:"dnsProviderReplication,omitempty"`
// ShootIssuers indicates whether shoot Issuers are on
ShootIssuers *ShootIssuers `json:"shootIssuers,omitempty"`
// Kind is extension type
Kind string `json:"kind"`
}

type ShootIssuers struct {
// Enabled indicates whether shoot Issuers are on
Enabled bool `json:"enabled"`
}

func NewCertConfig() *ExtensionProviderConfig {
return &ExtensionProviderConfig{
APIVersion: "service.cert.extensions.gardener.cloud/v1alpha1",
ShootIssuers: &ShootIssuers{Enabled: true},
Kind: "CertConfig",
}
}
Loading

0 comments on commit ca7f1a6

Please sign in to comment.