Skip to content

Commit

Permalink
add nodeipam controller
Browse files Browse the repository at this point in the history
  • Loading branch information
DockToFuture committed Sep 25, 2023
1 parent c9fbfe2 commit 7ac16a2
Show file tree
Hide file tree
Showing 6 changed files with 574 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/aws-cloud-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (

"k8s.io/apimachinery/pkg/util/wait"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/cloud-provider-aws/pkg/controllers/nodeipam"
"k8s.io/cloud-provider-aws/pkg/controllers/tagging"

awsv1 "k8s.io/cloud-provider-aws/pkg/providers/v1"
awsv2 "k8s.io/cloud-provider-aws/pkg/providers/v2"
"k8s.io/cloud-provider/app"
Expand Down Expand Up @@ -74,17 +76,30 @@ func main() {
Constructor: taggingControllerWrapper.StartTaggingControllerWrapper,
}

nodeIpamControllerWrapper := nodeipam.ControllerWrapper{}
nodeIpamControllerWrapper.Options.AddFlags(fss.FlagSet("nodeipam controller"))

nodeIpamControllerConstructor := app.ControllerInitFuncConstructor{
InitContext: app.ControllerInitContext{
ClientName: nodeipam.NodeIpamControllerClientName,
},
Constructor: nodeIpamControllerWrapper.StartNodeIpamControllerWrapper,
}

controllerInitializers[tagging.TaggingControllerKey] = taggingControllerConstructor
app.ControllersDisabledByDefault.Insert(tagging.TaggingControllerKey)

controllerAliases := names.CCMControllerAliases()
controllerAliases[tagging.TaggingControllerKey] = tagging.TaggingControllerKey

controllerInitializers[nodeipam.NodeIpamControllerKey] = nodeIpamControllerConstructor
app.ControllersDisabledByDefault.Insert(nodeipam.NodeIpamControllerKey)
command := app.NewCloudControllerManagerCommand(opts, cloudInitializer, controllerInitializers, controllerAliases, fss, wait.NeverStop)

if err := command.Execute(); err != nil {
klog.Fatalf("unable to execute command: %v", err)
}

}

func cloudInitializer(config *cloudcontrollerconfig.CompletedConfig) cloudprovider.Interface {
Expand Down
61 changes: 61 additions & 0 deletions pkg/controllers/nodeipam/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2023 The Kubernetes 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 nodeipam

import (
"sync"

"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
)

var register sync.Once

var (
workItemDuration = metrics.NewHistogramVec(
&metrics.HistogramOpts{
Name: "cloudprovider_aws_nodeipam_controller_work_item_duration_seconds",
Help: "workitem latency of workitem being in the queue and time it takes to process",
StabilityLevel: metrics.ALPHA,
Buckets: metrics.ExponentialBuckets(0.5, 1.5, 20),
},
[]string{"latency_type"})

workItemError = metrics.NewCounterVec(
&metrics.CounterOpts{
Name: "cloudprovider_aws_nodeipam_controller_work_item_errors_total",
Help: "any error in dequeueing the work queue and processing workItem",
StabilityLevel: metrics.ALPHA,
},
[]string{"error_type", "instance_id"})
)

// registerMetrics registers nodeipam-controller metrics.
func registerMetrics() {
register.Do(func() {
legacyregistry.MustRegister(workItemDuration)
legacyregistry.MustRegister(workItemError)
})
}

func recordWorkItemLatencyMetrics(latencyType string, timeTaken float64) {
workItemDuration.With(metrics.Labels{"latency_type": latencyType}).Observe(timeTaken)
}

func recordWorkItemErrorMetrics(errorType string, instanceID string) {
workItemError.With(metrics.Labels{"error_type": errorType, "instance_id": instanceID}).Inc()
}
Loading

0 comments on commit 7ac16a2

Please sign in to comment.