Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update controller-runtime #205

Merged
merged 4 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cmd/yawol-cloud-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/cache"

yawolv1beta1 "github.com/stackitcloud/yawol/api/v1beta1"
"github.com/stackitcloud/yawol/controllers/yawol-cloud-controller/controlcontroller"
Expand Down Expand Up @@ -138,10 +139,12 @@ func main() {
}

controlMgr, err := ctrl.NewManager(getConfigFromKubeconfigOrDie(controlKubeconfig), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: "0",
Port: 9443,
Namespace: *infrastructureDefaults.Namespace,
Scheme: scheme,
MetricsBindAddress: "0",
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.Namespaces = append(opts.Namespaces, *infrastructureDefaults.Namespace)
return cache.New(config, opts)
},
dergeberl marked this conversation as resolved.
Show resolved Hide resolved
LeaderElection: controlEnableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "4c878ae2.stackit.cloud",
Expand Down
20 changes: 14 additions & 6 deletions cmd/yawol-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/manager"

yawolv1beta1 "github.com/stackitcloud/yawol/api/v1beta1"
Expand Down Expand Up @@ -153,15 +155,17 @@ func main() {
loadBalancerMgr, err = ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddrLb,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "3a7ac996.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.Namespaces = append(opts.Namespaces, clusterNamespace)
return cache.New(config, opts)
},
dergeberl marked this conversation as resolved.
Show resolved Hide resolved
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -189,15 +193,17 @@ func main() {
loadBalancerSetMgr, err = ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddrLbs,
Port: 9444,
LeaderElection: enableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "rgp5vg43.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.Namespaces = append(opts.Namespaces, clusterNamespace)
return cache.New(config, opts)
},
dergeberl marked this conversation as resolved.
Show resolved Hide resolved
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -240,15 +246,17 @@ func main() {
loadBalancerMachineMgr, err = ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddrLbm,
Port: 9445,
LeaderElection: enableLeaderElection,
LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "tanf7ges.stackit.cloud",
LeaseDuration: &leasesDuration,
RenewDeadline: &leasesRenewDeadline,
RetryPeriod: &leasesRetryPeriod,
LeaderElectionResourceLock: leasesLeaderElectionResourceLock,
Namespace: clusterNamespace,
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.Namespaces = append(opts.Namespaces, clusterNamespace)
return cache.New(config, opts)
},
dergeberl marked this conversation as resolved.
Show resolved Hide resolved
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
15 changes: 5 additions & 10 deletions cmd/yawollet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"k8s.io/apimachinery/pkg/fields"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand Down Expand Up @@ -187,18 +188,12 @@ func main() {
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: false,
Namespace: namespace,

NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
dergeberl marked this conversation as resolved.
Show resolved Hide resolved
opts.SelectorsByObject = cache.SelectorsByObject{
&yawolv1beta1.LoadBalancer{}: cache.ObjectSelector{
Field: fields.SelectorFromSet(fields.Set{"metadata.name": loadbalancerName}),
},
&yawolv1beta1.LoadBalancerMachine{}: cache.ObjectSelector{
Field: fields.SelectorFromSet(fields.Set{"metadata.name": loadbalancerMachineName}),
},
opts.Namespaces = append(opts.Namespaces, namespace)
opts.ByObject = map[client.Object]cache.ByObject{
&yawolv1beta1.LoadBalancer{}: {Field: fields.SelectorFromSet(fields.Set{"metadata.name": loadbalancerName})},
&yawolv1beta1.LoadBalancerMachine{}: {Field: fields.SelectorFromSet(fields.Set{"metadata.name": loadbalancerMachineName})},
}

return cache.New(config, opts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/stackitcloud/yawol/internal/helper"
"github.com/stackitcloud/yawol/internal/helper/kubernetes"
Expand Down Expand Up @@ -139,8 +138,9 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&yawolv1beta1.LoadBalancer{}).
// we can't use Owns because it filters for ownerReference.controller==true which is not the case for our objects (as of now)
Watches(
dergeberl marked this conversation as resolved.
Show resolved Hide resolved
&source.Kind{Type: &yawolv1beta1.LoadBalancerSet{}},
&handler.EnqueueRequestForOwner{OwnerType: &yawolv1beta1.LoadBalancer{}},
&yawolv1beta1.LoadBalancerSet{},
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(),
&yawolv1beta1.LoadBalancer{}),
builder.WithPredicates(LoadBalancerSetPredicate()),
).
WithOptions(controller.Options{
Expand Down