Skip to content

Commit

Permalink
feat(*): add tencent cloud provider and clb plugin (#179)
Browse files Browse the repository at this point in the history
* feat(*): add tencent cloud provider and clb plugin

Signed-off-by: rockerchen <[email protected]>
  • Loading branch information
imroc authored Oct 29, 2024
1 parent e121bcc commit c680b41
Show file tree
Hide file tree
Showing 14 changed files with 1,332 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cloudprovider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ limitations under the License.
package cloudprovider

import (
"flag"

"github.com/BurntSushi/toml"
"github.com/openkruise/kruise-game/cloudprovider/options"
"k8s.io/klog/v2"
)

import "flag"

var Opt *Options

type Options struct {
Expand All @@ -47,17 +47,18 @@ type CloudProviderConfig struct {
AlibabaCloudOptions CloudProviderOptions
VolcengineOptions CloudProviderOptions
AmazonsWebServicesOptions CloudProviderOptions
TencentCloudOptions CloudProviderOptions
}

type tomlConfigs struct {
Kubernetes options.KubernetesOptions `toml:"kubernetes"`
AlibabaCloud options.AlibabaCloudOptions `toml:"alibabacloud"`
Volcengine options.VolcengineOptions `toml:"volcengine"`
AmazonsWebServices options.AmazonsWebServicesOptions `toml:"aws"`
TencentCloud options.TencentCloudOptions `toml:"tencentcloud"`
}

func (cf *ConfigFile) Parse() *CloudProviderConfig {

var config tomlConfigs
if _, err := toml.DecodeFile(cf.Path, &config); err != nil {
klog.Fatal(err)
Expand All @@ -68,6 +69,7 @@ func (cf *ConfigFile) Parse() *CloudProviderConfig {
AlibabaCloudOptions: config.AlibabaCloud,
VolcengineOptions: config.Volcengine,
AmazonsWebServicesOptions: config.AmazonsWebServices,
TencentCloudOptions: config.TencentCloud,
}
}

Expand Down
12 changes: 12 additions & 0 deletions cloudprovider/manager/provider_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package manager

import (
"context"

"github.com/openkruise/kruise-game/apis/v1alpha1"
"github.com/openkruise/kruise-game/cloudprovider"
"github.com/openkruise/kruise-game/cloudprovider/alibabacloud"
aws "github.com/openkruise/kruise-game/cloudprovider/amazonswebservices"
"github.com/openkruise/kruise-game/cloudprovider/kubernetes"
"github.com/openkruise/kruise-game/cloudprovider/tencentcloud"
volcengine "github.com/openkruise/kruise-game/cloudprovider/volcengine"
corev1 "k8s.io/api/core/v1"
log "k8s.io/klog/v2"
Expand Down Expand Up @@ -138,5 +140,15 @@ func NewProviderManager() (*ProviderManager, error) {
}
}

if configs.TencentCloudOptions.Valid() && configs.TencentCloudOptions.Enabled() {
// build and register tencent cloud provider
tcp, err := tencentcloud.NewTencentCloudProvider()
if err != nil {
log.Errorf("Failed to initialize tencentcloud provider.because of %s", err.Error())
} else {
pm.RegisterCloudProvider(tcp, configs.TencentCloudOptions)
}
}

return pm, nil
}
29 changes: 29 additions & 0 deletions cloudprovider/options/tencentcloud_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package options

type TencentCloudOptions struct {
Enable bool `toml:"enable"`
CLBOptions TencentCloudCLBOptions `toml:"clb"`
}

type TencentCloudCLBOptions struct {
MaxPort int32 `toml:"max_port"`
MinPort int32 `toml:"min_port"`
}

func (o TencentCloudOptions) Valid() bool {
clbOptions := o.CLBOptions

if clbOptions.MaxPort > 65535 {
return false
}

if clbOptions.MinPort < 1 {
return false
}

return true
}

func (o TencentCloudOptions) Enabled() bool {
return o.Enable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright 2024.
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 v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// DedicatedCLBListenerSpec defines the desired state of DedicatedCLBListener
type DedicatedCLBListenerSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="Value is immutable"
LbId string `json:"lbId"`
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="Value is immutable"
// +optional
LbRegion string `json:"lbRegion,omitempty"`
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="Value is immutable"
LbPort int64 `json:"lbPort"`
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="Value is immutable"
// +kubebuilder:validation:Enum=TCP;UDP
Protocol string `json:"protocol"`
// +optional
ExtensiveParameters string `json:"extensiveParameters,omitempty"`
// +optional
TargetPod *TargetPod `json:"targetPod,omitempty"`
}

type TargetPod struct {
PodName string `json:"podName"`
TargetPort int64 `json:"targetPort"`
}

// DedicatedCLBListenerStatus defines the observed state of DedicatedCLBListener
type DedicatedCLBListenerStatus struct {
ListenerId string `json:"listenerId,omitempty"`
// +kubebuilder:validation:Enum=Bound;Available;Pending;Failed;Deleting
State string `json:"state,omitempty"`
Message string `json:"message,omitempty"`
Address string `json:"address,omitempty"`
}

const (
DedicatedCLBListenerStateBound = "Bound"
DedicatedCLBListenerStateAvailable = "Available"
DedicatedCLBListenerStatePending = "Pending"
DedicatedCLBListenerStateFailed = "Failed"
DedicatedCLBListenerStateDeleting = "Deleting"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="LbId",type="string",JSONPath=".spec.lbId",description="CLB ID"
// +kubebuilder:printcolumn:name="LbPort",type="integer",JSONPath=".spec.lbPort",description="Port of CLB Listener"
// +kubebuilder:printcolumn:name="Pod",type="string",JSONPath=".spec.targetPod.podName",description="Pod name of target pod"
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="State of the dedicated clb listener"

// DedicatedCLBListener is the Schema for the dedicatedclblisteners API
type DedicatedCLBListener struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DedicatedCLBListenerSpec `json:"spec,omitempty"`
Status DedicatedCLBListenerStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// DedicatedCLBListenerList contains a list of DedicatedCLBListener
type DedicatedCLBListenerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DedicatedCLBListener `json:"items"`
}

func init() {
SchemeBuilder.Register(&DedicatedCLBListener{}, &DedicatedCLBListenerList{})
}
4 changes: 4 additions & 0 deletions cloudprovider/tencentcloud/apis/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package v1alpha1 contains API Schema definitions for the tencentcloud v1alpha1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=networking.cloud.tencent.com
package v1alpha1
38 changes: 38 additions & 0 deletions cloudprovider/tencentcloud/apis/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2024.
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 v1alpha1 contains API Schema definitions for the networking v1alpha1 API group
// +kubebuilder:validation:Required
// +kubebuilder:object:generate=true
// +groupName=networking.cloud.tencent.com

package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "networking.cloud.tencent.com", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
135 changes: 135 additions & 0 deletions cloudprovider/tencentcloud/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c680b41

Please sign in to comment.