Skip to content

Commit

Permalink
Update landscaper to version 99 (#224)
Browse files Browse the repository at this point in the history
* Update landscaper to version 99

* Removing deployer registrations
  • Loading branch information
robertgraeff authored Mar 13, 2024
1 parent 10cb6a1 commit d68206e
Show file tree
Hide file tree
Showing 197 changed files with 3,015 additions and 4,128 deletions.
44 changes: 44 additions & 0 deletions cmd/quickstart/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"time"

"k8s.io/apimachinery/pkg/util/wait"

extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -81,3 +83,45 @@ func removeObject(ctx context.Context, k8sClient client.Client, object client.Ob
return fmt.Errorf("object could not be removed %s", client.ObjectKeyFromObject(object).String())
}
}

func removeObjectsPatiently(ctx context.Context, k8sClient client.Client, crd *extv1.CustomResourceDefinition) error {
for k := range crd.Spec.Versions {
gvk := schema.GroupVersionKind{
Group: crd.Spec.Group,
Version: crd.Spec.Versions[k].Name,
Kind: crd.Spec.Names.Kind,
}

fmt.Printf("Removing objects of type %s\n", gvk)

objectList := &unstructured.UnstructuredList{}
objectList.SetGroupVersionKind(gvk)
if err := k8sClient.List(ctx, objectList); err != nil {
return err
}

for i := range objectList.Items {
item := &objectList.Items[i]
if err := k8sClient.Delete(ctx, item); err != nil {
return err
}
}

err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 4*time.Minute, true, func(ctx context.Context) (done bool, err error) {
fmt.Println("waiting for deployer registrations removed")

remainingObjectList := &unstructured.UnstructuredList{}
remainingObjectList.SetGroupVersionKind(gvk)
if err := k8sClient.List(ctx, remainingObjectList); err != nil {
return false, err
}

return len(remainingObjectList.Items) == 0, nil
})
if err != nil {
return fmt.Errorf("error while waiting for deployer registrations being removed: %w", err)
}
}

return nil
}
47 changes: 6 additions & 41 deletions cmd/quickstart/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"time"

"github.com/gardener/landscaper/apis/core/v1alpha1"
"github.com/go-logr/logr"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -17,7 +16,6 @@ import (
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -125,19 +123,9 @@ func (o *uninstallOptions) uninstallLandscaper(ctx context.Context, k8sClient cl
return err
}

if o.containsDeployerRegistration(crdList) {
deployerRegistrations := v1alpha1.DeployerRegistrationList{}
if err := k8sClient.List(ctx, &deployerRegistrations); err != nil {
return err
}

for _, registration := range deployerRegistrations.Items {
if err := k8sClient.Delete(ctx, &registration); err != nil {
return err
}
}

if err := waitForRegistrationsRemoved(ctx, k8sClient); err != nil {
deployerRegistrationCRD := o.getDeployerRegistrationCRD(crdList)
if deployerRegistrationCRD != nil {
if err := removeObjectsPatiently(ctx, k8sClient, deployerRegistrationCRD); err != nil {
return err
}
}
Expand Down Expand Up @@ -208,14 +196,14 @@ func (o *uninstallOptions) uninstallLandscaper(ctx context.Context, k8sClient cl
return nil
}

func (o *uninstallOptions) containsDeployerRegistration(crds *extv1.CustomResourceDefinitionList) bool {
func (o *uninstallOptions) getDeployerRegistrationCRD(crds *extv1.CustomResourceDefinitionList) *extv1.CustomResourceDefinition {
for i := range crds.Items {
if crds.Items[i].Name == "deployerregistrations.landscaper.gardener.cloud" {
return true
return &crds.Items[i]
}
}

return false
return nil
}

func (o *uninstallOptions) deleteCrds(ctx context.Context, k8sClient client.Client, crds *extv1.CustomResourceDefinitionList) error {
Expand Down Expand Up @@ -273,26 +261,3 @@ func (o *uninstallOptions) deleteWebhook(ctx context.Context, k8sClient client.C

return fmt.Errorf("webhook could not be removed %s", webhookname)
}

func waitForRegistrationsRemoved(ctx context.Context, k8sClient client.Client) error {
err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 4*time.Minute, true, func(ctx context.Context) (done bool, err error) {
fmt.Println("waiting for deployer registrations removed")

deployerRegistrations := v1alpha1.DeployerRegistrationList{}
if err := k8sClient.List(ctx, &deployerRegistrations); err != nil {
return false, err
}

if len(deployerRegistrations.Items) == 0 {
return true, nil
}

return false, nil
})

if err != nil {
return fmt.Errorf("error while waiting for deployer registrations being removed: %w", err)
}

return nil
}
41 changes: 20 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ require (
github.com/ahmetb/gen-crd-api-reference-docs v0.3.0
github.com/gardener/component-cli v0.55.0
github.com/gardener/component-spec/bindings-go v0.0.95
github.com/gardener/landscaper v0.98.0
github.com/gardener/landscaper/apis v0.98.0
github.com/go-logr/logr v1.3.0
github.com/gardener/landscaper v0.99.0
github.com/gardener/landscaper/apis v0.99.0
github.com/go-logr/logr v1.4.1
github.com/go-logr/zapr v1.2.4
github.com/golang/mock v1.6.0
github.com/mandelsoft/vfs v0.4.0
github.com/onsi/ginkgo v1.16.5
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
go.uber.org/zap v1.27.0
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
k8s.io/api v0.29.2
k8s.io/apiextensions-apiserver v0.29.2
k8s.io/apimachinery v0.29.2
k8s.io/client-go v0.29.2
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
sigs.k8s.io/controller-runtime v0.15.1
sigs.k8s.io/yaml v1.4.0
)
Expand All @@ -49,7 +50,7 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gardener/image-vector v0.10.0 // indirect
github.com/gardener/landscaper/controller-utils v0.98.0 // indirect
github.com/gardener/landscaper/controller-utils v0.99.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
Expand All @@ -63,7 +64,7 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-containerregistry v0.18.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
Expand Down Expand Up @@ -113,19 +114,18 @@ require (
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.uber.org/goleak v1.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
Expand All @@ -135,11 +135,10 @@ require (
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools/v3 v3.5.1 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/component-base v0.29.2 // indirect
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Expand Down
Loading

0 comments on commit d68206e

Please sign in to comment.