Skip to content

Commit

Permalink
feat: add autonomy controller
Browse files Browse the repository at this point in the history
feat: persist error keys
  • Loading branch information
vie-serendipity committed Jun 4, 2024
1 parent c61299e commit 7b6b0a9
Show file tree
Hide file tree
Showing 15 changed files with 880 additions and 25 deletions.
60 changes: 60 additions & 0 deletions cmd/yurt-manager/app/options/autonomycontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2024 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/autonomy/config"
)

type AutonomyControllerOptions struct {
*config.AutonomyControllerConfiguration
}

func NewAutonomyControllerOptions() *AutonomyControllerOptions {
return &AutonomyControllerOptions{
&config.AutonomyControllerConfiguration{
ConcurrentAutonomyWorkers: 3,
},
}
}

// AddFlags adds flags related to autonomy manager to the specified FlagSet.
func (o *AutonomyControllerOptions) AddFlags(fs *pflag.FlagSet) {
if o == nil {
return
}

fs.Int32Var(&o.ConcurrentAutonomyWorkers, "concurrent-autonomy-workers", o.ConcurrentAutonomyWorkers, "The number of autonomy controller that are allowed to reconcile concurrently. Larger number = more responsive autonomy controller, but more CPU (and network) load")
}

func (o *AutonomyControllerOptions) ApplyTo(cfg *config.AutonomyControllerConfiguration) error {
if o == nil {
return nil
}
cfg.ConcurrentAutonomyWorkers = o.ConcurrentAutonomyWorkers
return nil
}

func (o *AutonomyControllerOptions) Validate() []error {
if o == nil {
return nil
}
var errs []error
return errs
}
7 changes: 7 additions & 0 deletions cmd/yurt-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type YurtManagerOptions struct {
NodeBucketController *NodeBucketControllerOptions
EndPointsController *EndPointsControllerOptions
LoadBalancerSetController *LoadBalancerSetControllerOptions
AutonomyController *AutonomyControllerOptions
}

// NewYurtManagerOptions creates a new YurtManagerOptions with a default config.
Expand All @@ -63,6 +64,7 @@ func NewYurtManagerOptions() (*YurtManagerOptions, error) {
NodeBucketController: NewNodeBucketControllerOptions(),
EndPointsController: NewEndPointsControllerOptions(),
LoadBalancerSetController: NewLoadBalancerSetControllerOptions(),
AutonomyController: NewAutonomyControllerOptions(),
}

return &s, nil
Expand All @@ -85,6 +87,7 @@ func (y *YurtManagerOptions) Flags(allControllers, disabledByDefaultControllers
y.NodeBucketController.AddFlags(fss.FlagSet("nodebucket controller"))
y.EndPointsController.AddFlags(fss.FlagSet("endpoints controller"))
y.LoadBalancerSetController.AddFlags(fss.FlagSet("loadbalancerset controller"))
y.AutonomyController.AddFlags(fss.FlagSet("autonomy controller"))
return fss
}

Expand All @@ -106,6 +109,7 @@ func (y *YurtManagerOptions) Validate(allControllers []string, controllerAliases
errs = append(errs, y.NodeBucketController.Validate()...)
errs = append(errs, y.EndPointsController.Validate()...)
errs = append(errs, y.LoadBalancerSetController.Validate()...)
errs = append(errs, y.AutonomyController.Validate()...)
return utilerrors.NewAggregate(errs)
}

Expand Down Expand Up @@ -156,6 +160,9 @@ func (y *YurtManagerOptions) ApplyTo(c *config.Config, controllerAliases map[str
if err := y.LoadBalancerSetController.ApplyTo(&c.ComponentConfig.LoadBalancerSetController); err != nil {
return err
}
if err := y.AutonomyController.ApplyTo(&c.ComponentConfig.AutonomyController); err != nil {
return err
}
return nil
}

Expand Down
2 changes: 2 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 @@ const (
NodeLifeCycleController = "node-life-cycle-controller"
NodeBucketController = "node-bucket-controller"
LoadBalancerSetController = "load-balancer-set-controller"
AutonomyController = "autonomy-controller"
)

func YurtManagerControllerAliases() map[string]string {
Expand All @@ -62,5 +63,6 @@ func YurtManagerControllerAliases() map[string]string {
"nodelifecycle": NodeLifeCycleController,
"nodebucket": NodeBucketController,
"loadbalancerset": LoadBalancerSetController,
"autonomy": AutonomyController,
}
}
23 changes: 23 additions & 0 deletions pkg/apis/apps/v1beta1/conditions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2024 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 v1beta1

import v1 "k8s.io/api/core/v1"

const (
NodeAutonomy v1.NodeConditionType = "Autonomy"
)
5 changes: 5 additions & 0 deletions pkg/projectinfo/projectinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func GetAutonomyAnnotation() string {
return fmt.Sprintf("node.beta.%s/autonomy", labelPrefix)
}

// GetAutonomyStatusLabel returns label key for node autonomy status
func GetAutonomyStatusLabel() string {
return fmt.Sprintf("node.autonomy.%s/status", labelPrefix)
}

// normalizeGitCommit reserve 7 characters for gitCommit
func normalizeGitCommit(commit string) string {
if len(commit) > 7 {
Expand Down
Loading

0 comments on commit 7b6b0a9

Please sign in to comment.