Skip to content

Commit

Permalink
Update dependencies (#105)
Browse files Browse the repository at this point in the history
The `Watches...()` methods of the controller builder are now typed.
`admission.Decoder` might have changed from a struct to an interface. Did not check against the old version but it is an interface now.
  • Loading branch information
bastjan authored Jul 25, 2024
1 parent 5f4df92 commit 1d75410
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
controller-gen.kubebuilder.io/version: v0.15.0
name: zoneusageprofiles.cloudagent.appuio.io
spec:
group: cloudagent.appuio.io
Expand Down
30 changes: 4 additions & 26 deletions controllers/clustersource/clustersource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,11 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// ClusterSource is a cluster with added methods to be used as a source for controller Watches.
type ClusterSource interface {
cluster.Cluster

// SourceFor returns a controller.Watches source for the given object.
SourceFor(client.Object) source.SyncingSource
}

type clusterSource struct {
cluster.Cluster
}

// FromKubeConfig creates a ClusterSource from a kubeconfig.
func FromKubeConfig(kubeconfig []byte, scheme *runtime.Scheme) (ClusterSource, error) {
func FromKubeConfig(kubeconfig []byte, scheme *runtime.Scheme) (cluster.Cluster, error) {
rc, err := clientcmd.RESTConfigFromKubeConfig(kubeconfig)
if err != nil {
return nil, fmt.Errorf("unable to create rest config from kubeconfig: %w", err)
Expand All @@ -34,14 +20,12 @@ func FromKubeConfig(kubeconfig []byte, scheme *runtime.Scheme) (ClusterSource, e
return nil, fmt.Errorf("unable to setup cluster: %w", err)
}

return &clusterSource{
Cluster: clst,
}, nil
return clst, nil
}

// FromURLAndBearerToken creates a ClusterSource from a url and token.
// If more complex configuration is needed, use FromKubeConfig.
func FromURLAndBearerToken(url, token string, scheme *runtime.Scheme) (ClusterSource, error) {
func FromURLAndBearerToken(url, token string, scheme *runtime.Scheme) (cluster.Cluster, error) {
rc := &rest.Config{
Host: url, // yes this is the correct field, host accepts a url
BearerToken: token,
Expand All @@ -52,11 +36,5 @@ func FromURLAndBearerToken(url, token string, scheme *runtime.Scheme) (ClusterSo
return nil, fmt.Errorf("unable to setup cluster: %w", err)
}

return &clusterSource{
Cluster: clst,
}, nil
}

func (cs *clusterSource) SourceFor(obj client.Object) source.SyncingSource {
return source.Kind(cs.GetCache(), obj)
return clst, nil
}
26 changes: 7 additions & 19 deletions controllers/groupsync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/appuio/appuio-cloud-agent/controllers/clustersource"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// GroupSyncReconciler reconciles a Group object
Expand Down Expand Up @@ -132,37 +132,25 @@ func (r *GroupSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}

// SetupWithManager sets up the controller with the Manager.
func (r *GroupSyncReconciler) SetupWithManagerAndForeignCluster(mgr ctrl.Manager, foreign clustersource.ClusterSource) error {
func (r *GroupSyncReconciler) SetupWithManagerAndForeignCluster(mgr ctrl.Manager, foreign cluster.Cluster) error {
return ctrl.NewControllerManagedBy(mgr).
For(&userv1.Group{}).
WatchesRawSource(foreign.SourceFor(&controlv1.Team{}), handler.EnqueueRequestsFromMapFunc(teamMapper)).
WatchesRawSource(foreign.SourceFor(&controlv1.OrganizationMembers{}), handler.EnqueueRequestsFromMapFunc(organizationMembersMapper)).
WatchesRawSource(source.Kind(foreign.GetCache(), &controlv1.Team{}, handler.TypedEnqueueRequestsFromMapFunc(teamMapper))).
WatchesRawSource(source.Kind(foreign.GetCache(), &controlv1.OrganizationMembers{}, handler.TypedEnqueueRequestsFromMapFunc(organizationMembersMapper))).
Complete(r)
}

// teamMapper maps the combination of namespace and name of the manifest as the group name to reconcile.
// The namespace is the organization for the teams.
func teamMapper(ctx context.Context, o client.Object) []reconcile.Request {
team, ok := o.(*controlv1.Team)
if !ok {
log.FromContext(ctx).Error(nil, "expected a Team object got a %T", o)
return []reconcile.Request{}
}

func teamMapper(ctx context.Context, team *controlv1.Team) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{Name: fmt.Sprintf("%s+%s", team.Namespace, team.Name)}},
}
}

// organizationMembersMapper maps the namespace of the manifest as the group name to reconcile.
// The name is static and the organization is in the namespace field.
func organizationMembersMapper(ctx context.Context, o client.Object) []reconcile.Request {
member, ok := o.(*controlv1.OrganizationMembers)
if !ok {
log.FromContext(ctx).Error(nil, "expected a OrganizationMembers object got a %T", o)
return []reconcile.Request{}
}

func organizationMembersMapper(ctx context.Context, member *controlv1.OrganizationMembers) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{Name: member.Namespace}},
}
Expand Down
8 changes: 4 additions & 4 deletions controllers/userattributesync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/appuio/appuio-cloud-agent/controllers/clustersource"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// UserAttributeSyncReconciler reconciles a User object
Expand Down Expand Up @@ -89,9 +89,9 @@ func (r *UserAttributeSyncReconciler) Reconcile(ctx context.Context, req ctrl.Re
}

// SetupWithManager sets up the controller with the Manager.
func (r *UserAttributeSyncReconciler) SetupWithManagerAndForeignCluster(mgr ctrl.Manager, foreign clustersource.ClusterSource) error {
func (r *UserAttributeSyncReconciler) SetupWithManagerAndForeignCluster(mgr ctrl.Manager, foreign cluster.Cluster) error {
return ctrl.NewControllerManagedBy(mgr).
For(&userv1.User{}).
WatchesRawSource(foreign.SourceFor(&controlv1.User{}), &handler.EnqueueRequestForObject{}).
WatchesRawSource(source.Kind(foreign.GetCache(), &controlv1.User{}, &handler.TypedEnqueueRequestForObject[*controlv1.User]{})).
Complete(r)
}
2 changes: 1 addition & 1 deletion controllers/zoneusageprofileapply_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (r *ZoneUsageProfileApplyReconciler) ensureWatch(ctx context.Context, gvk s
toWatch := &unstructured.Unstructured{}
toWatch.SetGroupVersionKind(gvk)

err = r.controller.Watch(source.Kind(r.Cache, toWatch), handler.EnqueueRequestForOwner(r.Scheme, r.Client.RESTMapper(), &cloudagentv1.ZoneUsageProfile{}))
err = r.controller.Watch(source.Kind[client.Object](r.Cache, toWatch, handler.EnqueueRequestForOwner(r.Scheme, r.Client.RESTMapper(), &cloudagentv1.ZoneUsageProfile{})))
})
return err
}
Expand Down
7 changes: 4 additions & 3 deletions controllers/zoneusageprofilesync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/source"

cloudagentv1 "github.com/appuio/appuio-cloud-agent/api/v1"
"github.com/appuio/appuio-cloud-agent/controllers/clustersource"
)

// ZoneUsageProfileSyncReconciler reconciles a ZoneUsageProfile object
Expand Down Expand Up @@ -63,9 +64,9 @@ func (r *ZoneUsageProfileSyncReconciler) Reconcile(ctx context.Context, req ctrl
}

// SetupWithManager sets up the controller with the Manager.
func (r *ZoneUsageProfileSyncReconciler) SetupWithManagerAndForeignCluster(mgr ctrl.Manager, foreign clustersource.ClusterSource) error {
func (r *ZoneUsageProfileSyncReconciler) SetupWithManagerAndForeignCluster(mgr ctrl.Manager, foreign cluster.Cluster) error {
return ctrl.NewControllerManagedBy(mgr).
For(&cloudagentv1.ZoneUsageProfile{}).
WatchesRawSource(foreign.SourceFor(&controlv1.UsageProfile{}), &handler.EnqueueRequestForObject{}).
WatchesRawSource(source.Kind(foreign.GetCache(), &controlv1.UsageProfile{}, &handler.TypedEnqueueRequestForObject[*controlv1.UsageProfile]{})).
Complete(r)
}
73 changes: 36 additions & 37 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
module github.com/appuio/appuio-cloud-agent

go 1.22.1
go 1.22.5

require (
github.com/appuio/control-api v0.33.2
github.com/appuio/control-api v0.33.3
github.com/go-logr/logr v1.4.2
github.com/minio/pkg v1.7.5
github.com/openshift/api v0.0.0-20240301093301-ce10821dc999 // release-4.11
github.com/stretchr/testify v1.9.0
go.uber.org/multierr v1.11.0
gomodules.xyz/jsonpatch/v2 v2.4.0
gopkg.in/inf.v0 v0.9.1
k8s.io/api v0.29.2
k8s.io/apimachinery v0.29.2
k8s.io/client-go v0.29.2
sigs.k8s.io/controller-runtime v0.17.2
sigs.k8s.io/controller-tools v0.14.0
sigs.k8s.io/kind v0.22.0
k8s.io/api v0.30.3
k8s.io/apimachinery v0.30.3
k8s.io/client-go v0.30.3
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/controller-tools v0.15.0
sigs.k8s.io/kind v0.23.0
sigs.k8s.io/yaml v1.4.0
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.3 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.3 // indirect
github.com/go-openapi/jsonreference v0.20.5 // indirect
github.com/go-openapi/swag v0.22.10 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f // indirect
github.com/google/safetext v0.0.0-20240722112252-5a72de7e7962 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -58,31 +58,30 @@ require (
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.49.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.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/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
golang.org/x/tools v0.23.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.29.2 // indirect
k8s.io/component-base v0.29.2 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
k8s.io/apiextensions-apiserver v0.30.3 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240709000822-3c01b740850f // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
Loading

0 comments on commit 1d75410

Please sign in to comment.