Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
bazel-*
cluster/bin
MERGED_LICENSES
go.work
go.work.sum
vendor/
cloud-controller-manager
!cmd/cloud-controller-manager/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COPY cmd/ cmd/
COPY pkg/ pkg/
COPY providers/ providers/

RUN CGO_ENABLED=0 go build -o /go/bin/cloud-controller-manager ./cmd/cloud-controller-manager
RUN CGO_ENABLED=0 GOFLAGS=-mod=mod go build -o /go/bin/cloud-controller-manager ./cmd/cloud-controller-manager

FROM registry.k8s.io/build-image/go-runner:v2.4.0-go1.24.10-bookworm.0
COPY --from=builder --chown=root:root /go/bin/cloud-controller-manager /cloud-controller-manager
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Alternatively, you can run [push-images tool](https://github.com/kubernetes/clou
IMAGE_REPO=us-central1-docker.pkg.dev/my-project/my-repo IMAGE_TAG=v0 ./tools/push-images
```

IMAGE_REPO=us-central1-docker.pkg.dev/panpr-gke-dev/cloud-controller-manager IMAGE_TAG=test-p4sa ./tools/push-images


# Cross-compiling

Selecting the target platform is done with the `--platforms` option with `bazel`.
Expand Down
42 changes: 42 additions & 0 deletions cmd/cloud-controller-manager/gkemultinodecontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"context"

cloudprovider "k8s.io/cloud-provider"
nodeipamcontrolleroptions "k8s.io/cloud-provider-gcp/cmd/cloud-controller-manager/options"
nodeipamconfig "k8s.io/cloud-provider-gcp/pkg/controller/nodeipam/config"
"k8s.io/cloud-provider-gcp/pkg/controller/nodemanager"
"k8s.io/cloud-provider/app"
cloudcontrollerconfig "k8s.io/cloud-provider/app/config"
controllermanagerapp "k8s.io/controller-manager/app"
"k8s.io/controller-manager/controller"
"k8s.io/klog/v2"
)

// startGkeMultiNodeControllerWrapper is used to take cloud config as input and start the GKE service controller
func startGkeMultiNodeControllerWrapper(initContext app.ControllerInitContext, completedConfig *cloudcontrollerconfig.CompletedConfig, cloud cloudprovider.Interface, nodeIPAMControllerOptions nodeipamcontrolleroptions.NodeIPAMControllerOptions) app.InitFunc {
nodeIPAMControllerOptions.ApplyTo(nodeIPAMControllerOptions.NodeIPAMControllerConfiguration)
return func(ctx context.Context, controllerContext controllermanagerapp.ControllerContext) (controller.Interface, bool, error) {
return startGkeMultiNodeController(ctx, initContext, controllerContext, completedConfig, cloud, *nodeIPAMControllerOptions.NodeIPAMControllerConfiguration)
}
}

func startGkeMultiNodeController(ctx context.Context, initContext app.ControllerInitContext, controlexContext controllermanagerapp.ControllerContext, completedConfig *cloudcontrollerconfig.CompletedConfig, cloud cloudprovider.Interface, nodeIPAMConfig nodeipamconfig.NodeIPAMControllerConfiguration) (controller.Interface, bool, error) {
if !enableMultiProject {
klog.Warning("MultiNodeController is disabled (enable-multi-project is false)")
return nil, false, nil
}
nodeMgrCtrl, err := nodemanager.NewNodeManagerController(
completedConfig.ClientBuilder.ClientOrDie(initContext.ClientName),
controlexContext.InformerFactory,
completedConfig, controlexContext, cloud, nodeIPAMConfig)
if err != nil {
klog.Errorf("Failed to start node manager controller: %v", err)
return nil, false, nil
}

go nodeMgrCtrl.Run(ctx.Done())

return nil, true, nil
}
3 changes: 2 additions & 1 deletion cmd/cloud-controller-manager/gkenetworkparamsetcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
networkinformers "github.com/GoogleCloudPlatform/gke-networking-api/client/network/informers/externalversions"
cloudprovider "k8s.io/cloud-provider"
gkenetworkparamsetcontroller "k8s.io/cloud-provider-gcp/pkg/controller/gkenetworkparamset"
nodeipam "k8s.io/cloud-provider-gcp/pkg/controller/nodeipam"
"k8s.io/cloud-provider-gcp/pkg/controller/nodeipam/ipam"
"k8s.io/cloud-provider-gcp/providers/gce"
"k8s.io/cloud-provider/app"
Expand Down Expand Up @@ -73,7 +74,7 @@ func startGkeNetworkParamsController(ccmConfig *cloudcontrollerconfig.CompletedC
// with stack type and returns a list of typed cidrs and error
func validClusterCIDR(clusterCIDRFromFlag string) ([]*net.IPNet, error) {
// failure: bad cidrs in config
clusterCIDRs, dualStack, err := processCIDRs(clusterCIDRFromFlag)
clusterCIDRs, dualStack, err := nodeipam.ProcessCIDRs(clusterCIDRFromFlag)
if err != nil {
return nil, err
}
Expand Down
24 changes: 20 additions & 4 deletions cmd/cloud-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/cloud-provider-gcp/providers/gce"
_ "k8s.io/cloud-provider-gcp/providers/gce"

"k8s.io/cloud-provider/app"
"k8s.io/cloud-provider/app/config"
cloudcontrollerconfig "k8s.io/cloud-provider/app/config"
"k8s.io/cloud-provider/names"
"k8s.io/cloud-provider/options"
cliflag "k8s.io/component-base/cli/flag"
Expand All @@ -45,6 +45,9 @@ const (
gkeServiceLBControllerName = "gke-service-lb-controller"
gkeServiceControllerClientName = "gke-service-controller"
gkeServiceAlias = "gke-service"
multiNodeControllerName = "gke-multi-node-controller"
multiNodeControllerClientName = "gke-multi-node-controller"
multiNodeControllerAlias = "gke-multi-node"
)

// enableMultiProject is bound to a command-line flag. When true, it enables the
Expand Down Expand Up @@ -111,6 +114,18 @@ func main() {
aliasMap := names.CCMControllerAliases()
aliasMap["nodeipam"] = kcmnames.NodeIpamController
aliasMap[gkeServiceAlias] = gkeServiceLBControllerName

controllerInitializers[multiNodeControllerName] = app.ControllerInitFuncConstructor{
InitContext: app.ControllerInitContext{
ClientName: multiNodeControllerClientName,
},
Constructor: func(initContext app.ControllerInitContext, completedConfig *cloudcontrollerconfig.CompletedConfig, cloud cloudprovider.Interface) app.InitFunc {
return startGkeMultiNodeControllerWrapper(initContext, completedConfig, cloud, nodeIpamController.nodeIPAMControllerOptions)
},
}
Comment on lines +118 to +125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented in 3c0ad5f#r2607023536 , this can be added as an opt-in new controller, that runs independently of the other controller, so users can use the flags to enable or disable one or other controller ...

// app.ControllersDisabledByDefault.Insert(names.CloudNodeController)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this multiNodeControllerName has to be disabled by default , and better to have all things aggregated in Line 108-110 so we do not have risk of drifting the code by using these conventions

aliasMap[multiNodeControllerAlias] = multiNodeControllerName

command := app.NewCloudControllerManagerCommand(ccmOptions, cloudInitializer, controllerInitializers, aliasMap, fss, wait.NeverStop)

logs.InitLogs()
Expand All @@ -121,7 +136,7 @@ func main() {
}
}

func cloudInitializer(config *config.CompletedConfig) cloudprovider.Interface {
func cloudInitializer(config *cloudcontrollerconfig.CompletedConfig) cloudprovider.Interface {
cloudConfig := config.ComponentConfig.KubeCloudShared.CloudProvider

// initialize cloud provider with the cloud provider name and config file provided
Expand All @@ -142,14 +157,15 @@ func cloudInitializer(config *config.CompletedConfig) cloudprovider.Interface {
}

if enableMultiProject {
klog.Infof("HELLO PP - Testing")
gceCloud, ok := (cloud).(*gce.Cloud)
if !ok {
// Fail-fast: If enableMultiProject is set, the cloud provider MUST
// be GCE. A non-GCE provider indicates a misconfiguration. Ideally,
// we never expect this to be executed.
klog.Fatalf("multi-project mode requires GCE cloud provider, but got %T", cloud)
}
gceCloud.SetProjectFromNodeProviderID(true)
gceCloud.SetProjectFromNodeProviderID(false)
}

if enableDiscretePortForwarding {
Expand Down
Loading