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

feat: add hub leader config controller #2299

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
45 changes: 43 additions & 2 deletions charts/yurt-manager/templates/yurt-manager-auto-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ metadata:
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: yurt-manager-hubleaderconfig-controller
namespace: {{ .Release.Namespace }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: yurt-manager-load-balancer-set-controller
namespace: {{ .Release.Namespace }}
Expand Down Expand Up @@ -476,12 +482,34 @@ rules:
- apiGroups:
- apps.openyurt.io
resources:
- nodepool
- nodepool/status
- nodepools
- nodepools/status
verbs:
- get
- patch
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: yurt-manager-hubleaderconfig-controller
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
- get
- patch
- update
- apiGroups:
- apps.openyurt.io
resources:
- nodepools
- nodepools/status
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -1042,6 +1070,19 @@ subjects:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: yurt-manager-hubleaderconfig-controller-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: yurt-manager-hubleaderconfig-controller
subjects:
- kind: ServiceAccount
name: yurt-manager-hubleaderconfig-controller
namespace: {{ .Release.Namespace }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: yurt-manager-load-balancer-set-controller-binding
roleRef:
Expand Down
71 changes: 71 additions & 0 deletions cmd/yurt-manager/app/options/hubleaderconfigcontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright 2025 The OpenYurt Authors.

Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

import (
"github.com/spf13/pflag"

"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/hubleaderconfig/config"
)

type HubLeaderConfigControllerOptions struct {
*config.HubLeaderConfigControllerConfiguration
}

func NewHubLeaderConfigControllerOptions(hubleaderNamespace string) *HubLeaderConfigControllerOptions {
return &HubLeaderConfigControllerOptions{
&config.HubLeaderConfigControllerConfiguration{
ConcurrentHubLeaderConfigWorkers: 3,
HubLeaderNamespace: hubleaderNamespace,
},

Check warning on line 34 in cmd/yurt-manager/app/options/hubleaderconfigcontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/hubleaderconfigcontroller.go#L29-L34

Added lines #L29 - L34 were not covered by tests
}
}

// AddFlags adds flags related to hubleader for yurt-manager to the specified FlagSet.
func (h *HubLeaderConfigControllerOptions) AddFlags(fs *pflag.FlagSet) {
if h == nil {
return

Check warning on line 41 in cmd/yurt-manager/app/options/hubleaderconfigcontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/hubleaderconfigcontroller.go#L39-L41

Added lines #L39 - L41 were not covered by tests
}

fs.Int32Var(
&h.ConcurrentHubLeaderConfigWorkers,
"concurrent-hubleaderconfig-workers",
h.ConcurrentHubLeaderConfigWorkers,
"The number of nodepool objects that are allowed to reconcile concurrently.",
)

Check warning on line 49 in cmd/yurt-manager/app/options/hubleaderconfigcontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/hubleaderconfigcontroller.go#L44-L49

Added lines #L44 - L49 were not covered by tests
}

// ApplyTo fills up hubleader config with options.
func (h *HubLeaderConfigControllerOptions) ApplyTo(cfg *config.HubLeaderConfigControllerConfiguration) error {
if h == nil {
return nil

Check warning on line 55 in cmd/yurt-manager/app/options/hubleaderconfigcontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/hubleaderconfigcontroller.go#L53-L55

Added lines #L53 - L55 were not covered by tests
}

cfg.ConcurrentHubLeaderConfigWorkers = h.ConcurrentHubLeaderConfigWorkers
cfg.HubLeaderNamespace = h.HubLeaderNamespace

Check warning on line 59 in cmd/yurt-manager/app/options/hubleaderconfigcontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/hubleaderconfigcontroller.go#L58-L59

Added lines #L58 - L59 were not covered by tests

return nil

Check warning on line 61 in cmd/yurt-manager/app/options/hubleaderconfigcontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/hubleaderconfigcontroller.go#L61

Added line #L61 was not covered by tests
}

// Validate checks validation of HubLeaderControllerOptions.
func (h *HubLeaderConfigControllerOptions) Validate() []error {
if h == nil {
return nil

Check warning on line 67 in cmd/yurt-manager/app/options/hubleaderconfigcontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/hubleaderconfigcontroller.go#L65-L67

Added lines #L65 - L67 were not covered by tests
}
errs := []error{}
return errs

Check warning on line 70 in cmd/yurt-manager/app/options/hubleaderconfigcontroller.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/hubleaderconfigcontroller.go#L69-L70

Added lines #L69 - L70 were not covered by tests
}
11 changes: 9 additions & 2 deletions cmd/yurt-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@
GatewayInternalSvcController *GatewayInternalSvcControllerOptions
GatewayPublicSvcController *GatewayPublicSvcControllerOptions
HubLeaderController *HubLeaderControllerOptions
HubLeaderConfigController *HubLeaderConfigControllerOptions
}

// NewYurtManagerOptions creates a new YurtManagerOptions with a default config.
func NewYurtManagerOptions() (*YurtManagerOptions, error) {

genericOptions := NewGenericOptions()

Check warning on line 54 in cmd/yurt-manager/app/options/options.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/options.go#L54

Added line #L54 was not covered by tests
s := YurtManagerOptions{
Generic: NewGenericOptions(),
Generic: genericOptions,

Check warning on line 56 in cmd/yurt-manager/app/options/options.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/options.go#L56

Added line #L56 was not covered by tests
DelegateLeaseController: NewDelegateLeaseControllerOptions(),
PodBindingController: NewPodBindingControllerOptions(),
DaemonPodUpdaterController: NewDaemonPodUpdaterControllerOptions(),
Expand All @@ -73,6 +74,7 @@
GatewayInternalSvcController: NewGatewayInternalSvcControllerOptions(),
GatewayPublicSvcController: NewGatewayPublicSvcControllerOptions(),
HubLeaderController: NewHubLeaderControllerOptions(),
HubLeaderConfigController: NewHubLeaderConfigControllerOptions(genericOptions.WorkingNamespace),

Check warning on line 77 in cmd/yurt-manager/app/options/options.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/options.go#L77

Added line #L77 was not covered by tests
}

return &s, nil
Expand Down Expand Up @@ -101,6 +103,7 @@
y.GatewayInternalSvcController.AddFlags(fss.FlagSet("gatewayinternalsvc controller"))
y.GatewayPublicSvcController.AddFlags(fss.FlagSet("gatewaypublicsvc controller"))
y.HubLeaderController.AddFlags(fss.FlagSet("hubleader controller"))
y.HubLeaderConfigController.AddFlags(fss.FlagSet("hubleaderconfig controller"))

Check warning on line 106 in cmd/yurt-manager/app/options/options.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/options.go#L106

Added line #L106 was not covered by tests
return fss
}

Expand Down Expand Up @@ -128,6 +131,7 @@
errs = append(errs, y.GatewayInternalSvcController.Validate()...)
errs = append(errs, y.GatewayPublicSvcController.Validate()...)
errs = append(errs, y.HubLeaderController.Validate()...)
errs = append(errs, y.HubLeaderConfigController.Validate()...)

Check warning on line 134 in cmd/yurt-manager/app/options/options.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/options.go#L134

Added line #L134 was not covered by tests
return utilerrors.NewAggregate(errs)
}

Expand Down Expand Up @@ -196,6 +200,9 @@
if err := y.HubLeaderController.ApplyTo(&c.ComponentConfig.HubLeaderController); err != nil {
return err
}
if err := y.HubLeaderConfigController.ApplyTo(&c.ComponentConfig.HubLeaderConfigController); err != nil {
return err

Check warning on line 204 in cmd/yurt-manager/app/options/options.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/app/options/options.go#L203-L204

Added lines #L203 - L204 were not covered by tests
}
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/yurt-manager/names/controller_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
NodeBucketController = "node-bucket-controller"
LoadBalancerSetController = "load-balancer-set-controller"
HubLeaderController = "hubleader-controller"
HubLeaderConfigController = "hubleaderconfig-controller"
)

func YurtManagerControllerAliases() map[string]string {
Expand All @@ -61,5 +62,7 @@
"nodelifecycle": NodeLifeCycleController,
"nodebucket": NodeBucketController,
"loadbalancerset": LoadBalancerSetController,
"hubleader": HubLeaderController,
"hubleaderconfig": HubLeaderConfigController,

Check warning on line 66 in cmd/yurt-manager/names/controller_names.go

View check run for this annotation

Codecov / codecov/patch

cmd/yurt-manager/names/controller_names.go#L65-L66

Added lines #L65 - L66 were not covered by tests
}
}
4 changes: 4 additions & 0 deletions pkg/yurtmanager/controller/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
csrapproverconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/csrapprover/config"
daemonpodupdaterconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/daemonpodupdater/config"
hubleaderconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/hubleader/config"
hubleadercfgconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/hubleaderconfig/config"
loadbalancersetconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/loadbalancerset/loadbalancerset/config"
nodebucketconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/nodebucket/config"
nodepoolconfig "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/nodepool/config"
Expand Down Expand Up @@ -106,6 +107,9 @@ type YurtManagerConfiguration struct {

// HubLeaderController holds configuration for HubLeaderController related features.
HubLeaderController hubleaderconfig.HubLeaderControllerConfiguration

// HubLeaderConfigController holds configuration for HubLeaderController related features.
HubLeaderConfigController hubleadercfgconfig.HubLeaderConfigControllerConfiguration
}

type GenericConfiguration struct {
Expand Down
22 changes: 19 additions & 3 deletions pkg/yurtmanager/controller/base/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"github.com/openyurtio/openyurt/cmd/yurt-manager/names"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/csrapprover"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/daemonpodupdater"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/hubleader"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/hubleaderconfig"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/loadbalancerset/loadbalancerset"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/nodebucket"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/nodelifecycle"
Expand Down Expand Up @@ -97,6 +99,8 @@
register(names.NodeLifeCycleController, nodelifecycle.Add)
register(names.NodeBucketController, nodebucket.Add)
register(names.LoadBalancerSetController, loadbalancerset.Add)
register(names.HubLeaderController, hubleader.Add)
register(names.HubLeaderConfigController, hubleaderconfig.Add)

Check warning on line 103 in pkg/yurtmanager/controller/base/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/base/controller.go#L102-L103

Added lines #L102 - L103 were not covered by tests

return controllers
}
Expand Down Expand Up @@ -134,7 +138,11 @@

func SetupWithManager(ctx context.Context, c *config.CompletedConfig, m manager.Manager) error {
for controllerName, fn := range NewControllerInitializers() {
if !app.IsControllerEnabled(controllerName, ControllersDisabledByDefault, c.ComponentConfig.Generic.Controllers) {
if !app.IsControllerEnabled(
controllerName,
ControllersDisabledByDefault,
c.ComponentConfig.Generic.Controllers,
) {

Check warning on line 145 in pkg/yurtmanager/controller/base/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/base/controller.go#L141-L145

Added lines #L141 - L145 were not covered by tests
klog.Warningf("Controller %v is disabled", controllerName)
continue
}
Expand All @@ -150,8 +158,16 @@
}
}

if app.IsControllerEnabled(names.NodeLifeCycleController, ControllersDisabledByDefault, c.ComponentConfig.Generic.Controllers) ||
app.IsControllerEnabled(names.PodBindingController, ControllersDisabledByDefault, c.ComponentConfig.Generic.Controllers) {
if app.IsControllerEnabled(
names.NodeLifeCycleController,
ControllersDisabledByDefault,
c.ComponentConfig.Generic.Controllers,
) ||
app.IsControllerEnabled(
names.PodBindingController,
ControllersDisabledByDefault,
c.ComponentConfig.Generic.Controllers,
) {

Check warning on line 170 in pkg/yurtmanager/controller/base/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/base/controller.go#L161-L170

Added lines #L161 - L170 were not covered by tests
// Register spec.NodeName field indexers
if err := m.GetFieldIndexer().IndexField(context.TODO(), &v1.Pod{}, "spec.nodeName", func(rawObj client.Object) []string {
pod, ok := rawObj.(*v1.Pod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ type ReconcileHubLeader struct {
Configuration config.HubLeaderControllerConfiguration
}

// +kubebuilder:rbac:groups=apps.openyurt.io,resources=nodepool,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps.openyurt.io,resources=nodepool/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps.openyurt.io,resources=nodepools,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps.openyurt.io,resources=nodepools/status,verbs=get;update;patch

// Reconcile reads that state of the cluster for a HubLeader object and makes changes based on the state read
// and what is in the HubLeader.Spec
Expand Down
24 changes: 24 additions & 0 deletions pkg/yurtmanager/controller/hubleaderconfig/config/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2025 The OpenYurt Authors.

Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

// HubLeaderConfigControllerConfiguration contains elements describing HubLeaderConfigController.
type HubLeaderConfigControllerConfiguration struct {
ConcurrentHubLeaderConfigWorkers int32

HubLeaderNamespace string
}
Loading
Loading