Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor porter #132

Merged
merged 1 commit into from Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 34 additions & 43 deletions Makefile
@@ -1,8 +1,8 @@

# Image URL to use all building/pushing image targets
IMG_MANAGER ?= kubespheredev/porter:v0.3-dev
IMG_AGENT ?= kubespheredev/porter-agent:v0.3-dev
NAMESPACE ?= porter-system
IMG_MANAGER ?= kubespheredev/porter:v0.4
IMG_AGENT ?= kubespheredev/porter-agent:v0.4
BRANCH ?= release

CRD_OPTIONS ?= "crd:trivialVersions=true"

Expand All @@ -15,42 +15,43 @@ endif

all: manager

# Run go fmt against code
fmt:
go fmt ./pkg/... ./cmd/... ./api/... ./pkg/controllers/...

# Run go vet against code
vet:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go vet ./pkg/... ./cmd/... ./pkg/controllers/...

# Run tests
test: fmt vet
go test -v ./api/... ./controllers/... ./pkg/... -coverprofile cover.out
go test -v ./api/... ./pkg/controllers/... ./pkg/... -coverprofile cover.out

# Build manager binary
manager: fmt vet
go build -o bin/manager github.com/kubesphere/porter/cmd/manager
#CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o bin/manager github.com/kubesphere/porter/cmd/manager
CGO_ENABLED=0 go build -o bin/manager github.com/kubesphere/porter/cmd/manager

# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crd/bases

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
kubectl apply -f config/crd/bases
kustomize build config/default | kubectl apply -f -
deploy: generate
ifeq ($(uname), Darwin)
sed -i '' -e 's@image: .*@image: '"${IMG_AGENT}"'@' ./config/${BRANCH}/agent_image_patch.yaml
sed -i '' -e 's@image: .*@image: '"${IMG_MANAGER}"'@' ./config/${BRANCH}/manager_image_patch.yaml
else
sed -i -e 's@image: .*@image: '"${IMG_AGENT}"'@' ./config/${BRANCH}/agent_image_patch.yaml
sed -i -e 's@image: .*@image: '"${IMG_MANAGER}"'@' ./config/${BRANCH}/manager_image_patch.yaml
endif
kustomize build config/${BRANCH} -o deploy/porter.yaml
@echo "Done, the yaml is in deploy folder named 'porter.yaml'"

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./api/..." paths="./controllers/..." output:crd:artifacts:config=config/crd/bases
# Run go fmt against code
fmt:
go fmt ./pkg/... ./cmd/... ./api/... ./controllers/...

# Run go vet against code
vet:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go vet ./pkg/... ./cmd/... ./controllers/...

$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=porter-manager-role webhook paths="./api/..." paths="./pkg/controllers/..." output:crd:artifacts:config=config/crd/bases

controller-gen:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.0
go get sigs.k8s.io/controller-tools/cmd/controller-gen@
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
Expand All @@ -59,25 +60,15 @@ endif
clean-up:
./hack/cleanup.sh

release:
export DOCKER_CLI_EXPERIMENTAL=enabled
GOOS=linux GOARCH=amd64 go build -o bin/manager-linux-amd64 github.com/kubesphere/porter/cmd/manager
GOOS=linux GOARCH=amd64 go build -o bin/agent-linux-amd64 github.com/kubesphere/porter/cmd/agent
GOOS=linux GOARCH=arm64 go build -o bin/manager-linux-arm64 github.com/kubesphere/porter/cmd/manager
GOOS=linux GOARCH=arm64 go build -o bin/agent-linux-arm64 github.com/kubesphere/porter/cmd/agent
docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG_AGENT} -f ./cmd/agent/Dockerfile . --push
docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG_MANAGER} -f ./cmd/manager/Dockerfile . --push

ifeq ($(uname), Darwin)
sed -i '' -e 's@image: .*@image: '"${IMG_AGENT}"'@' ./config/release/agent_image_patch.yaml
sed -i '' -e 's@image: .*@image: '"${IMG_MANAGER}"'@' ./config/release/manager_image_patch.yaml
else
sed -i -e 's@image: .*@image: '"${IMG_AGENT}"'@' ./config/release/agent_image_patch.yaml
sed -i -e 's@image: .*@image: '"${IMG_MANAGER}"'@' ./config/release/manager_image_patch.yaml
endif
kustomize build config/release -o deploy/porter.yaml
@echo "Done, the yaml is in deploy folder named 'porter.yaml'"
release: deploy
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager-linux-amd64 github.com/kubesphere/porter/cmd/manager
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/agent-linux-amd64 github.com/kubesphere/porter/cmd/agent
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/manager-linux-arm64 github.com/kubesphere/porter/cmd/manager
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/agent-linux-arm64 github.com/kubesphere/porter/cmd/agent
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG_AGENT} -f ./cmd/agent/Dockerfile . --push
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG_MANAGER} -f ./cmd/manager/Dockerfile . --push

install-travis:
echo "install kubebuilder/kustomize etc."
chmod +x ./hack/*.sh
./hack/install_tools.sh
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -21,7 +21,7 @@ However, the service is hard to expose in a bare metal cluster since Kubernetes

- ECMP routing load balancing
- BGP dynamic routing configuration
- VIP management
- EIP management
- LoadBalancerIP assignment in Kubernetes services
- Installation with Helm Chart
- Dynamic BGP server configuration through CRD
Expand Down
5 changes: 0 additions & 5 deletions api/v1alpha1/eip_types.go
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
package v1alpha1

import (
"github.com/kubesphere/porter/pkg/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -66,7 +65,3 @@ type EipList struct {
func init() {
SchemeBuilder.Register(&Eip{}, &EipList{})
}

func (e Eip) GetEIPSize() int {
return util.GetValidAddressCount(e.Spec.Address)
}
117 changes: 117 additions & 0 deletions api/v1alpha2/bgpconf_types.go
@@ -0,0 +1,117 @@
/*
Copyright 2019 The Kubesphere 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 v1alpha2

import (
"bytes"
"encoding/json"
"github.com/golang/protobuf/jsonpb"
api "github.com/osrg/gobgp/api"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type NodeConfStatus struct {
RouterId string `json:"routerId,omitempty"`
}

// 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.

// BgpConfStatus defines the observed state of BgpConf
type BgpConfStatus struct {
NodesConfStatus map[string]NodeConfStatus `json:"nodesConfStatus,omitempty"`
}

// +kubebuilder:rbac:groups=network.kubesphere.io,resources=bgpconfs,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=network.kubesphere.io,resources=bgpconfs/status,verbs=get;update;patch

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:scope=Cluster

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

Spec BgpConfSpec `json:"spec,omitempty"`
Status BgpConfStatus `json:"status,omitempty"`
}

func (c BgpConfSpec) ConverToGoBgpGlabalConf() (*api.Global, error) {
jsonBytes, err := json.Marshal(c)
if err != nil {
return nil, err
}

var result api.Global
m := jsonpb.Unmarshaler{}
return &result, m.Unmarshal(bytes.NewReader(jsonBytes), &result)
}

func ConverFromGoBgpGlobalConf(global *api.Global) (*BgpConfSpec, error) {
m := jsonpb.Marshaler{}
jsonStr, err := m.MarshalToString(global)
if err != nil {
return nil, err
}

var result BgpConfSpec

return &result, json.Unmarshal([]byte(jsonStr), &result)
}

// Configuration parameters relating to the global BGP router.
type BgpConfSpec struct {
As uint32 `json:"as,omitempty"`
RouterId string `json:"routerId,omitempty"`
ListenPort int32 `json:"listenPort,omitempty"`
ListenAddresses []string `json:"listenAddresses,omitempty"`
Families []uint32 `json:"families,omitempty"`
UseMultiplePaths bool `json:"useMultiplePaths,omitempty"`
GracefulRestart *GracefulRestart `json:"gracefulRestart,omitempty"`
}

type GracefulRestart struct {
Enabled bool `json:"enabled,omitempty"`
RestartTime uint32 `json:"restartTime,omitempty"`
HelperOnly bool `json:"helperOnly,omitempty"`
DeferralTime uint32 `json:"deferralTime,omitempty"`
NotificationEnabled bool `json:"notificationEnabled,omitempty"`
LonglivedEnabled bool `json:"longlivedEnabled,omitempty"`
StaleRoutesTime uint32 `json:"staleRoutesTime,omitempty"`
PeerRestartTime uint32 `json:"peerRestartTime,omitempty"`
PeerRestarting bool `json:"peerRestarting,omitempty"`
LocalRestarting bool `json:"localRestarting,omitempty"`
Mode string `json:"mode,omitempty"`
}

// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

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

func init() {
SchemeBuilder.Register(&BgpConf{}, &BgpConfList{})
}