Skip to content

Commit

Permalink
Feat: add cloud provider & network plugin (openkruise#16)
Browse files Browse the repository at this point in the history
* Feat: add cloud provider & network plugin
  • Loading branch information
chrisliu1995 authored Feb 8, 2023
1 parent cde5c22 commit 6b58728
Show file tree
Hide file tree
Showing 42 changed files with 3,337 additions and 148 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN go mod download
COPY main.go main.go
COPY apis/ apis/
COPY pkg/ pkg/
COPY cloudprovider/ cloudprovider/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./pkg/... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./pkg/... ./cloudprovider/... -coverprofile cover.out

##@ Build

Expand Down
21 changes: 16 additions & 5 deletions apis/v1alpha1/gameserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ import (
)

const (
GameServerStateKey = "game.kruise.io/gs-state"
GameServerOpsStateKey = "game.kruise.io/gs-opsState"
GameServerUpdatePriorityKey = "game.kruise.io/gs-update-priority"
GameServerDeletePriorityKey = "game.kruise.io/gs-delete-priority"
GameServerDeletingKey = "game.kruise.io/gs-deleting"
GameServerStateKey = "game.kruise.io/gs-state"
GameServerOpsStateKey = "game.kruise.io/gs-opsState"
GameServerUpdatePriorityKey = "game.kruise.io/gs-update-priority"
GameServerDeletePriorityKey = "game.kruise.io/gs-delete-priority"
GameServerDeletingKey = "game.kruise.io/gs-deleting"
GameServerNetworkType = "game.kruise.io/network-type"
GameServerNetworkConf = "game.kruise.io/network-conf"
GameServerNetworkDisabled = "game.kruise.io/network-disabled"
GameServerNetworkStatus = "game.kruise.io/network-status"
GameServerNetworkTriggerTime = "game.kruise.io/network-trigger-time"
)

// GameServerSpec defines the desired state of GameServer
Expand Down Expand Up @@ -109,6 +114,12 @@ type NetworkStatus struct {

type NetworkState string

const (
NetworkReady NetworkState = "Ready"
NetworkWaiting NetworkState = "Waiting"
NetworkNotReady NetworkState = "NotReady"
)

type NetworkAddress struct {
IP string `json:"ip"`
// TODO add IPv6
Expand Down
61 changes: 61 additions & 0 deletions cloudprovider/alibabacloud/alibabacloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2022 The Kruise 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 alibabacloud

import (
"github.com/openkruise/kruise-game/cloudprovider"
"k8s.io/klog/v2"
)

const (
AlibabaCloud = "AlibabaCloud"
)

var (
alibabaCloudProvider = &Provider{
plugins: make(map[string]cloudprovider.Plugin),
}
)

type Provider struct {
plugins map[string]cloudprovider.Plugin
}

func (ap *Provider) Name() string {
return AlibabaCloud
}

func (ap *Provider) ListPlugins() (map[string]cloudprovider.Plugin, error) {
if ap.plugins == nil {
return make(map[string]cloudprovider.Plugin), nil
}

return ap.plugins, nil
}

// register plugin of cloud provider and different cloud providers
func (ap *Provider) registerPlugin(plugin cloudprovider.Plugin) {
name := plugin.Name()
if name == "" {
klog.Fatal("empty plugin name")
}
ap.plugins[name] = plugin
}

func NewAlibabaCloudProvider() (cloudprovider.CloudProvider, error) {
return alibabaCloudProvider, nil
}
4 changes: 4 additions & 0 deletions cloudprovider/alibabacloud/apis/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package v1 contains API Schema definitions for the alibabacloud v1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=alibabacloud.com
package v1
102 changes: 102 additions & 0 deletions cloudprovider/alibabacloud/apis/v1/poddnat_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright 2022 The Kruise 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 v1

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

func init() {
SchemeBuilder.Register(&PodDNAT{}, &PodDNATList{})
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PodDNAT let you specficy DNAT rule for pod on nat gateway
type PodDNAT struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec is the desired state of the PodDNAT.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
Spec PodDNATSpec `json:"spec,omitempty"`

// 'Status is the current state of the dnat.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
// +optional
Status PodDNATStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PodDNATList is a collection of PodDNAT.
type PodDNATList struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
metav1.ListMeta `json:"metadata,omitempty"`

// Items is the list of PodDNAT.
Items []PodDNAT `json:"items"`
}

// PodDNATSpec describes the PodDNAT the user wishes to exist.
type PodDNATSpec struct {
VSwitch *string `json:"vswitch,omitempty"` // deprecated
ENI *string `json:"eni,omitempty"` // deprecated
ZoneID *string `json:"zoneID,omitempty"`
ExternalIP *string `json:"externalIP,omitempty"`
ExternalPort *string `json:"externalPort,omitempty"` // deprecated
InternalIP *string `json:"internalIP,omitempty"` // pod IP may change
InternalPort *string `json:"internalPort,omitempty"` // deprecated
Protocol *string `json:"protocol,omitempty"`
TableId *string `json:"tableId,omitempty"` // natGateway ID
EntryId *string `json:"entryId,omitempty"` // deprecated
PortMapping []PortMapping `json:"portMapping,omitempty"`
}

type PortMapping struct {
ExternalPort string `json:"externalPort,omitempty"`
InternalPort string `json:"internalPort,omitempty"`
}

// PodDNATStatus is the current state of the dnat.
type PodDNATStatus struct {
// created create status
// +optional
Created *string `json:"created,omitempty"` // deprecated

// entries
// +optional
Entries []Entry `json:"entries,omitempty"`
}

// Entry record for forwardEntry
type Entry struct {
ExternalPort string `json:"externalPort,omitempty"`
ExternalIP string `json:"externalIP,omitempty"`
InternalPort string `json:"internalPort,omitempty"`
InternalIP string `json:"internalIP,omitempty"`

ForwardEntryID string `json:"forwardEntryId,omitempty"`
IPProtocol string `json:"ipProtocol,omitempty"`
}
23 changes: 23 additions & 0 deletions cloudprovider/alibabacloud/apis/v1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// NOTE: Boilerplate only. Ignore this file.

// Package v1 contains API Schema definitions for the alibabacloud v1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=alibabacloud.com

package v1

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

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "alibabacloud.com", Version: "v1"}

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

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Loading

0 comments on commit 6b58728

Please sign in to comment.