Skip to content

Commit

Permalink
Merge pull request #2 from sp-yduck/feature/keep-session
Browse files Browse the repository at this point in the history
update proxmox-go version
  • Loading branch information
sp-yduck authored Nov 11, 2023
2 parents ea8952e + 3376ac7 commit 850a908
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 431 deletions.
234 changes: 117 additions & 117 deletions cmd/proxmox-cloud-controller-manager.go
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
/*
Copyright 2020 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.
*/

// This file should be written by each cloud provider.
// For an minimal working example, please refer to k8s.io/cloud-provider/sample/basic_main.go
// For more details, please refer to k8s.io/kubernetes/cmd/cloud-controller-manager/main.go

// Package main provides the CCM implementation.
package main

import (
"os"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/wait"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/cloud-provider/app"
"k8s.io/cloud-provider/app/config"
"k8s.io/cloud-provider/options"
"k8s.io/component-base/cli"
cliflag "k8s.io/component-base/cli/flag"
_ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugins
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
"k8s.io/klog/v2"

"github.com/sp-yduck/cloud-provider-proxmox/pkg/cloudprovider"
)

func main() {
ccmOptions, err := options.NewCloudControllerManagerOptions()
if err != nil {
klog.Fatalf("unable to initialize command options: %v", err)
}

fss := cliflag.NamedFlagSets{}
command := app.NewCloudControllerManagerCommand(ccmOptions, cloudInitializer, controllerInitializers(), fss, wait.NeverStop)

command.Flags().VisitAll(func(flag *pflag.Flag) {
if flag.Name == "cloud-provider" {
if err := flag.Value.Set(proxmox.ProviderName); err != nil {
klog.Fatalf("unable to set cloud-provider flag value: %s", err)
}
}
})

code := cli.Run(command)
os.Exit(code)
}

// If custom ClientNames are used, as below, then the controller will not use
// the API server bootstrapped RBAC, and instead will require it to be installed
// separately.
func controllerInitializers() map[string]app.ControllerInitFuncConstructor {
klog.Info("initializing controllers")

controllerInitializers := app.DefaultInitFuncConstructors
if constructor, ok := controllerInitializers["cloud-node"]; ok {
constructor.InitContext.ClientName = proxmox.ClientName
controllerInitializers["cloud-node"] = constructor
}

if constructor, ok := controllerInitializers["cloud-node-lifecycle"]; ok {
constructor.InitContext.ClientName = proxmox.ClientName
controllerInitializers["cloud-node-lifecycle"] = constructor
}

if constructor, ok := controllerInitializers["service"]; ok {
constructor.InitContext.ClientName = proxmox.ClientName
controllerInitializers["service"] = constructor
}

if constructor, ok := controllerInitializers["route"]; ok {
constructor.InitContext.ClientName = proxmox.ClientName
controllerInitializers["route"] = constructor
}

return controllerInitializers
}

func cloudInitializer(config *config.CompletedConfig) cloudprovider.Interface {
klog.Info("initializing cloud")

cloudConfig := config.ComponentConfig.KubeCloudShared.CloudProvider

// initialize cloud provider with the cloud provider name and config file provided
cloud, err := cloudprovider.InitCloudProvider(cloudConfig.Name, cloudConfig.CloudConfigFile)
if err != nil {
klog.Fatalf("Cloud provider could not be initialized: %v", err)
}

if cloud == nil {
klog.Fatalf("Cloud provider is nil")
}

if !cloud.HasClusterID() {
if config.ComponentConfig.KubeCloudShared.AllowUntaggedCloud {
klog.Warning("detected a cluster without a ClusterID. A ClusterID will be required in the future. Please tag your cluster to avoid any future issues")
} else {
klog.Fatalf("no ClusterID found. A ClusterID is required for the cloud provider to function properly. This check can be bypassed by setting the allow-untagged-cloud option")
}
}

return cloud
}
/*
Copyright 2020 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.
*/

// This file should be written by each cloud provider.
// For an minimal working example, please refer to k8s.io/cloud-provider/sample/basic_main.go
// For more details, please refer to k8s.io/kubernetes/cmd/cloud-controller-manager/main.go

// Package main provides the CCM implementation.
package main

import (
"os"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/wait"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/cloud-provider/app"
"k8s.io/cloud-provider/app/config"
"k8s.io/cloud-provider/options"
"k8s.io/component-base/cli"
cliflag "k8s.io/component-base/cli/flag"
_ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugins
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
"k8s.io/klog/v2"

"github.com/sp-yduck/cloud-provider-proxmox/pkg/cloudprovider"
)

func main() {
ccmOptions, err := options.NewCloudControllerManagerOptions()
if err != nil {
klog.Fatalf("unable to initialize command options: %v", err)
}

fss := cliflag.NamedFlagSets{}
command := app.NewCloudControllerManagerCommand(ccmOptions, cloudInitializer, controllerInitializers(), fss, wait.NeverStop)

command.Flags().VisitAll(func(flag *pflag.Flag) {
if flag.Name == "cloud-provider" {
if err := flag.Value.Set(proxmox.ProviderName); err != nil {
klog.Fatalf("unable to set cloud-provider flag value: %s", err)
}
}
})

code := cli.Run(command)
os.Exit(code)
}

// If custom ClientNames are used, as below, then the controller will not use
// the API server bootstrapped RBAC, and instead will require it to be installed
// separately.
func controllerInitializers() map[string]app.ControllerInitFuncConstructor {
klog.Info("initializing controllers")

controllerInitializers := app.DefaultInitFuncConstructors
if constructor, ok := controllerInitializers["cloud-node"]; ok {
constructor.InitContext.ClientName = proxmox.ClientName
controllerInitializers["cloud-node"] = constructor
}

if constructor, ok := controllerInitializers["cloud-node-lifecycle"]; ok {
constructor.InitContext.ClientName = proxmox.ClientName
controllerInitializers["cloud-node-lifecycle"] = constructor
}

if constructor, ok := controllerInitializers["service"]; ok {
constructor.InitContext.ClientName = proxmox.ClientName
controllerInitializers["service"] = constructor
}

if constructor, ok := controllerInitializers["route"]; ok {
constructor.InitContext.ClientName = proxmox.ClientName
controllerInitializers["route"] = constructor
}

return controllerInitializers
}

func cloudInitializer(config *config.CompletedConfig) cloudprovider.Interface {
klog.Info("initializing cloud")

cloudConfig := config.ComponentConfig.KubeCloudShared.CloudProvider

// initialize cloud provider with the cloud provider name and config file provided
cloud, err := cloudprovider.InitCloudProvider(cloudConfig.Name, cloudConfig.CloudConfigFile)
if err != nil {
klog.Fatalf("Cloud provider could not be initialized: %v", err)
}

if cloud == nil {
klog.Fatalf("Cloud provider is nil")
}

if !cloud.HasClusterID() {
if config.ComponentConfig.KubeCloudShared.AllowUntaggedCloud {
klog.Warning("detected a cluster without a ClusterID. A ClusterID will be required in the future. Please tag your cluster to avoid any future issues")
} else {
klog.Fatalf("no ClusterID found. A ClusterID is required for the cloud provider to function properly. This check can be bypassed by setting the allow-untagged-cloud option")
}
}

return cloud
}
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/pkg/errors v0.9.1
github.com/sp-yduck/proxmox-go v0.0.0-20230817151858-dfc9563487ca
github.com/sp-yduck/proxmox-go v0.0.0-alpha22
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -32,7 +32,7 @@ require (
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
Expand Down Expand Up @@ -111,6 +111,4 @@ require (
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

// replace cloud.google.com/go => cloud.google.com/go v0.100.2
)
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo=
Expand Down Expand Up @@ -264,8 +265,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js=
github.com/sp-yduck/proxmox-go v0.0.0-20230817151858-dfc9563487ca h1:CBqb4OSv1SNBF8CndaF8odjctOWSBDOXZJf2piZiEg8=
github.com/sp-yduck/proxmox-go v0.0.0-20230817151858-dfc9563487ca/go.mod h1:XtUQue7w5tuB6c7xputkhnN+A3EZbzDWq+uXmlkOPfQ=
github.com/sp-yduck/proxmox-go v0.0.0-alpha22 h1:xMY7SBfieHUXMZY0f7AShO2fmGJtZZkmGbI/9PnmQ/c=
github.com/sp-yduck/proxmox-go v0.0.0-alpha22/go.mod h1:iEI7ilRwyUaWvoxuXs/30UJ2f8Z2TWXCW1cZ3QeU2JY=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
Expand Down
Loading

0 comments on commit 850a908

Please sign in to comment.