Skip to content

Commit

Permalink
Merge pull request #294 from amal-thundiyil/refactor
Browse files Browse the repository at this point in the history
cleanup: minor changes to codebase
  • Loading branch information
ks-ci-bot authored Jul 15, 2022
2 parents 4ab158e + 4b8e1f9 commit e47ceae
Show file tree
Hide file tree
Showing 36 changed files with 281 additions and 177 deletions.
18 changes: 12 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ assignees: ""
---

**Describe the bug**
A clear and concise description of what the bug is.

<!-- A clear and concise description of what the bug is. -->

**To Reproduce**

<!--
Steps to reproduce the behaviour:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
4. See error
-->

**Expected behaviour**
What did you expect to happen?

<!-- What did you expect to happen? -->

**Output**
Add the output you're seeing to help explain your problem.

<!-- Add the output you're seeing to help explain your problem. -->

**Version Info**

- Version of Kubernetes:
- Version of OpenELB:
- Version of Kubernetes:
- Version of OpenELB:
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ labels: kind/feature
assignees: ""
---

→ If you have a general conceptual idea please [start a discussion](https://github.com/openelb/openelb/discussions/new?category=ideas)! We try and keep our issue tracker to focus on specific changes.
<!-- → If you have a general conceptual idea please [start a discussion](https://github.com/openelb/openelb/discussions/new?category=ideas)! We try and keep our issue tracker to focus on specific changes. -->

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. eg: I'm always frustrated when ...
<!-- A clear and concise description of what the problem is. eg: I'm always frustrated when ... -->

**Describe the solution you'd like**
A clear and concise description of what you want to happen.
<!-- A clear and concise description of what you want to happen. -->

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Additional context**
Add any other context or screenshots about the feature request here.
<!-- Add any other context or screenshots about the feature request here. -->
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

## Description

**What type of PR is this ?:**

<!-- Thanks for your contribution! Describe your changes in a few sentences. Try to include discussion of tradeoffs or alternatives you considered when writing this code. -->

## Related links:
Expand Down
26 changes: 12 additions & 14 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
name: Go
on: [push,pull_request]
on: [push, pull_request]
jobs:

build:
name: Build And Test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.16
id: go

- name: Set up Go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.16
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Install CI tools
run: make install-travis
- name: Test
run: make test
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Install CI tools
run: make install-tools
- name: Test
run: make test
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# Image URL to use all building/pushing image targets
BRANCH ?= release
RELEASE_TAG = $(shell cat VERSION)
IMG_MANAGER ?= kubesphere/openelb:$(RELEASE_TAG)
IMG_AGENT ?= kubesphere/openelb-agent:$(RELEASE_TAG)
IMG_PROXY ?= kubesphere/openelb-proxy:$(RELEASE_TAG)
IMG_FORWARD ?= kubesphere/openelb-forward:$(RELEASE_TAG)
DOCKER_USERNAME ?= kubesphere
IMG_MANAGER ?= $(DOCKER_USERNAME)/openelb:$(RELEASE_TAG)
IMG_AGENT ?= $(DOCKER_USERNAME)/openelb-agent:$(RELEASE_TAG)
IMG_PROXY ?= $(DOCKER_USERNAME)/openelb-proxy:$(RELEASE_TAG)
IMG_FORWARD ?= $(DOCKER_USERNAME)/openelb-forward:$(RELEASE_TAG)

CRD_OPTIONS ?= "crd:trivialVersions=true"

Expand All @@ -28,7 +29,7 @@ vet:

# Run tests
test: fmt vet
KUBEBUILDER_ASSETS=$(shell $(GOBIN)/setup-envtest use -p path 1.19.x) go test -v ./api/... ./pkg/controllers/... ./pkg/... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(GOBIN)/setup-envtest use -p path 1.19.x)" go test -v ./api/... ./pkg/controllers/... ./pkg/... -coverprofile cover.out

# Build manager binary
manager: fmt vet
Expand All @@ -40,13 +41,13 @@ 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
sed -i '' -e 's@NodeProxyDefaultForwardImage string = \".*\"@NodeProxyDefaultForwardImage string = \"'"${IMG_FORWARD}"'\"@' ./pkg/constant/constants.go
sed -i '' -e 's@NodeProxyDefaultProxyImage string = \".*\"@NodeProxyDefaultProxyImage string = \"'"${IMG_PROXY}"'\"@' ./pkg/constant/constants.go
sed -i '' -e 's@NodeProxyDefaultForwardImage string = \".*\"@NodeProxyDefaultForwardImage string = \"'"${IMG_FORWARD}"'\"@' ./pkg/constant/constant.go
sed -i '' -e 's@NodeProxyDefaultProxyImage string = \".*\"@NodeProxyDefaultProxyImage string = \"'"${IMG_PROXY}"'\"@' ./pkg/constant/constant.go
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
sed -i -e 's@NodeProxyDefaultForwardImage string = \".*\"@NodeProxyDefaultForwardImage string = \"'"${IMG_FORWARD}"'\"@' ./pkg/constant/constants.go
sed -i -e 's@NodeProxyDefaultProxyImage string = \".*\"@NodeProxyDefaultProxyImage string = \"'"${IMG_PROXY}"'\"@' ./pkg/constant/constants.go
sed -i -e 's@NodeProxyDefaultForwardImage string = \".*\"@NodeProxyDefaultForwardImage string = \"'"${IMG_FORWARD}"'\"@' ./pkg/constant/constant.go
sed -i -e 's@NodeProxyDefaultProxyImage string = \".*\"@NodeProxyDefaultProxyImage string = \"'"${IMG_PROXY}"'\"@' ./pkg/constant/constant.go
endif
kustomize build config/${BRANCH} -o deploy/openelb.yaml
@echo "Done, the yaml is in deploy folder named 'openelb.yaml'"
Expand All @@ -58,7 +59,7 @@ generate: controller-gen

controller-gen:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/[email protected]
go install sigs.k8s.io/controller-tools/cmd/[email protected]
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
Expand All @@ -79,7 +80,7 @@ release: deploy
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG_PROXY} -f ./images/proxy/Dockerfile . --push
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform linux/amd64,linux/arm64 -t ${IMG_FORWARD} -f ./images/forward/Dockerfile . --push

install-travis:
install-tools:
echo "install kubebuilder/kustomize etc."
chmod +x ./hack/*.sh
./hack/install_tools.sh
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

27 changes: 14 additions & 13 deletions api/v1alpha2/bgpconf_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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"
Expand Down Expand Up @@ -55,19 +56,6 @@ type BgpConf struct {
Status BgpConfStatus `json:"status,omitempty"`
}

func (c BgpConfSpec) ConverToGoBgpGlabalConf() (*api.Global, error) {
c.AsPerRack = nil

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)
}

// Configuration parameters relating to the global BGP router.
type BgpConfSpec struct {
As uint32 `json:"as,omitempty"`
Expand Down Expand Up @@ -104,6 +92,19 @@ type BgpConfList struct {
Items []BgpConf `json:"items"`
}

func (c BgpConfSpec) ToGoBgpGlobalConf() (*api.Global, error) {
c.AsPerRack = nil

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 init() {
SchemeBuilder.Register(&BgpConf{}, &BgpConfList{})
}
57 changes: 29 additions & 28 deletions api/v1alpha2/bgppeer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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"
Expand Down Expand Up @@ -177,7 +178,33 @@ type AfiSafi struct {
AddPaths *AddPaths `json:"addPaths,omitempty"`
}

func (c BgpPeerSpec) ConverToGoBgpPeer() (*api.Peer, error) {
type EbgpMultihop struct {
Enabled bool `json:"enabled,omitempty"`
MultihopTtl uint32 `json:"multihopTtl,omitempty"`
}

type BgpPeerSpec struct {
Conf *PeerConf `json:"conf,omitempty"`
EbgpMultihop *EbgpMultihop `json:"ebgpMultihop,omitempty"`
Timers *Timers `json:"timers,omitempty"`
Transport *Transport `json:"transport,omitempty"`
GracefulRestart *GracefulRestart `json:"gracefulRestart,omitempty"`
AfiSafis []*AfiSafi `json:"afiSafis,omitempty"`

NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"`
}

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

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

func (c BgpPeerSpec) ToGoBgpPeer() (*api.Peer, error) {
c.NodeSelector = nil

jsonBytes, err := json.Marshal(c)
Expand All @@ -190,7 +217,7 @@ func (c BgpPeerSpec) ConverToGoBgpPeer() (*api.Peer, error) {
return &result, m.Unmarshal(bytes.NewReader(jsonBytes), &result)
}

func ConverStatusFromGoBgpPeer(peer *api.Peer) (NodePeerStatus, error) {
func GetStatusFromGoBgpPeer(peer *api.Peer) (NodePeerStatus, error) {
var (
nodePeerStatus NodePeerStatus
)
Expand All @@ -216,32 +243,6 @@ func ConverStatusFromGoBgpPeer(peer *api.Peer) (NodePeerStatus, error) {
return nodePeerStatus, err
}

type EbgpMultihop struct {
Enabled bool `json:"enabled,omitempty"`
MultihopTtl uint32 `json:"multihopTtl,omitempty"`
}

type BgpPeerSpec struct {
Conf *PeerConf `json:"conf,omitempty"`
EbgpMultihop *EbgpMultihop `json:"ebgpMultihop,omitempty"`
Timers *Timers `json:"timers,omitempty"`
Transport *Transport `json:"transport,omitempty"`
GracefulRestart *GracefulRestart `json:"gracefulRestart,omitempty"`
AfiSafis []*AfiSafi `json:"afiSafis,omitempty"`

NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"`
}

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

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

func init() {
SchemeBuilder.Register(&BgpPeer{}, &BgpPeerList{})
}
Loading

0 comments on commit e47ceae

Please sign in to comment.