Skip to content

Commit c097bdc

Browse files
pogossianartashesbalabekyanasaroyan
authored
vnet CRD (#19)
* Ci implementation (#1) * added github workflow, minor fixes in configloader * Multi arch build (#2) * multi architecture build * increase ci job timeout * module path changed * Deploy kustomize (#3) * kustomize image tag * added custom-env for manager * Linter warnings (#4) * linter warnings fixes * fixed respBodyClose func in api_handler and ctrl returns in controller * added awesome full yaml in samples * rm vaMode from sample vnet yaml * Ci release (#7) * Makefile clean-up * added release in makefile && release workflow for tags * makefile release add image tag * fixes #6 * added VNet sample * vnet readme fix * Vnet sample (#8) * added VNet sample * vnet readme fix * update vnet sample * Update README.md * vnet dev v1alpha1 (#12) * vnet-dev initial commit * controller-api full link * fix: change Netris API module to 'netris-api-go' * Update main.yml * Update main.yml * Update main.yml * change netris api package name * change netris api package name * refactor: reconcile cycle improvements * refactor: change file structure * feat: add netris data storage * add licenses * feat: add netris data storage Co-authored-by: Artashes Balabekyan <[email protected]> * added helm chart (#13) * chart init * added rbac in helm chart * added rbac to helm template script * fix deployment and service in helm chart * refactor: update required fields * CI fix (#14) * added ssh-key in main CI * added GIT_AUTH_TOKEN in main ci Build and push step * added experimental key mount in dockerfile * debuging * fix ssh key in docker buildkit * ssh_private_key_ci full path in docker buildkit * dockerfile fixes * cleanup and prepared for release * fixed release CI * CI Release steps reorder * fix: if port is untagged set vlanID to 1 * fix: don't requeue after create * fix: change the order of checks in reconcile function * deploy readme fix * deploy readme fix * deploy readme fix * Netris Helm repository (#15) * update helm-repo from makefile helm target * Update deploy README * change go version to 1.14 * update netrisapi package version in go.mod * TLS insecure option functionality * Vnetmeta (#16) added vnetmeta kind Co-authored-by: Artashes Balabekyan <[email protected]> * updateted Helm * refactor: use logger for log messages * fix: deletion logic. don't use finalizer for vnetmeta CR * fix: deletion logic. don't use finalizer for vnetmeta CR. Update netrisapi module * feat: log after vnet is deleted * refactor: requeue option, logging mechanism. Support requeue option. Don't exit with error from reconciler, return nil and requeue. * comment: comment Cred and NStorage datastrucutres * added logger and requeue option * add branches in CI job * CI only for tags * fix helm NOPERATOR_DEV_MODE env * UP deplot readme tag * fix: set provisioning field to 1, and state field to previous field * up appVersion * helm version up * Update README.md * Update README.md * fix: set the state is 'active' when not defined in yaml * fix: handle the switchPort state field * fix: gateways and switchPorts fields are not mandatory * feat: when 'netris.imported' is true in annotations, identify vnet by name instead of creating new one. * info log when not imported * fix: change guestTenants type to string * update netris api package. fix: handle guestTenants field * refactor: change gateways structure and calculation * fix: use requeueInterval for reconcile period * added ebgp sample yaml (#18) * fix: netris import flag name in annotations * added resource importing Co-authored-by: Artashes Balabekyan <[email protected]> Co-authored-by: asaroyan <[email protected]>
1 parent 4f6eebe commit c097bdc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3293
-547
lines changed

.github/workflows/main.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Test, Build and Push
2+
on:
3+
push:
4+
# Sequence of patterns matched against refs/tags
5+
tags:
6+
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
7+
jobs:
8+
main:
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 20
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
15+
- name: Git configs and known_hosts
16+
run: |
17+
export known_hosts=$(ssh-keyscan github.com)
18+
git config --global --add url."[email protected]:".insteadOf "https://github.com/"
19+
20+
- name: Install SSH key
21+
uses: shimataro/ssh-key-action@v2
22+
with:
23+
key: ${{ secrets.SSH_PRIVATE_KEY_NETRISAPI }}
24+
known_hosts: ${known_hosts}
25+
26+
- name: Switch the default system shell
27+
run: sudo rm /bin/sh; sudo ln -s bash /bin/sh
28+
29+
- name: Make test
30+
run: CONTROLLER_HOST="example.com" make test
31+
32+
- name: Prepare
33+
id: prep
34+
run: |
35+
DOCKER_IMAGE=${GITHUB_REPOSITORY}
36+
VERSION=edge
37+
if [[ $GITHUB_REF == refs/tags/* ]]; then
38+
VERSION=${GITHUB_REF#refs/tags/}
39+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
40+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
41+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
42+
VERSION=pr-${{ github.event.number }}
43+
fi
44+
TAGS="${DOCKER_IMAGE}:${VERSION}"
45+
if [ "${{ github.event_name }}" = "push" ]; then
46+
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
47+
fi
48+
echo ::set-output name=version::${VERSION}
49+
echo ::set-output name=tags::${TAGS}
50+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
51+
52+
- name: Set up QEMU
53+
uses: docker/setup-qemu-action@v1
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v1
57+
58+
- name: Login to DockerHub
59+
if: github.event_name != 'pull_request'
60+
uses: docker/login-action@v1
61+
with:
62+
username: ${{ secrets.DOCKER_USERNAME }}
63+
password: ${{ secrets.DOCKER_PASSWORD }}
64+
65+
- name: Build and push
66+
uses: docker/build-push-action@v2
67+
with:
68+
context: .
69+
file: ./Dockerfile
70+
platforms: linux/amd64,linux/arm64
71+
push: ${{ github.event_name != 'pull_request' }}
72+
tags: ${{ steps.prep.outputs.tags }}
73+
ssh: |
74+
ssh_private_key_ci=/home/runner/.ssh/id_rsa
75+
labels: |
76+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
77+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
78+
org.opencontainers.image.revision=${{ github.sha }}

.github/workflows/release.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Create release
2+
on:
3+
push:
4+
# Sequence of patterns matched against refs/tags
5+
tags:
6+
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
7+
jobs:
8+
build:
9+
name: Upload Release Asset
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
- name: Git configs and known_hosts
15+
run: |
16+
export known_hosts=$(ssh-keyscan github.com)
17+
git config --global --add url."[email protected]:".insteadOf "https://github.com/"
18+
- name: Install SSH key
19+
uses: shimataro/ssh-key-action@v2
20+
with:
21+
key: ${{ secrets.SSH_PRIVATE_KEY_NETRISAPI }}
22+
known_hosts: ${known_hosts}
23+
- name: Generate Manifests
24+
run: make release
25+
- name: Create Release
26+
id: create_release
27+
uses: actions/create-release@v1
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
with:
31+
tag_name: ${{ github.ref }}
32+
release_name: Release ${{ github.ref }}
33+
draft: false
34+
prerelease: false
35+
- name: Upload Release Asset
36+
uses: actions/upload-release-asset@v1
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
with:
40+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
41+
asset_path: ./deploy/netris-operator.yaml
42+
asset_name: netris-operator.yaml
43+
asset_content_type: text/yaml
44+
- name: Upload Release Asset - CRD
45+
uses: actions/upload-release-asset@v1
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
with:
49+
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
50+
asset_path: ./deploy/netris-operator.crds.yaml
51+
asset_name: netris-operator.crds.yaml
52+
asset_content_type: text/yaml

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ bin
2222
*.swp
2323
*.swo
2424
*~
25+
.netrc
26+
testbin

Dockerfile

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
# syntax=docker/dockerfile:experimental
12
# Build the manager binary
23
FROM golang:1.13 as builder
34

45
WORKDIR /workspace
6+
7+
# Config ssh private key
8+
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
9+
RUN git config --global --add url."[email protected]:".insteadOf "https://github.com/"
10+
511
# Copy the Go Modules manifests
612
COPY go.mod go.mod
713
COPY go.sum go.sum
814
# cache deps before building and copying source so that we don't need to re-download as much
915
# and so that source changes don't invalidate our downloaded layer
10-
RUN go mod download
16+
RUN --mount=type=ssh,id=ssh_private_key_ci go mod download
1117

1218
# Copy the go source
1319
COPY main.go main.go
1420
COPY api/ api/
1521
COPY controllers/ controllers/
22+
COPY configloader/ configloader/
1623

1724
# Build
18-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
25+
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager main.go
1926

2027
# Use distroless as minimal base image to package the manager binary
2128
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

+41-24
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
# Current Operator version
2-
VERSION ?= 0.0.1
3-
# Default bundle image tag
4-
BUNDLE_IMG ?= controller-bundle:$(VERSION)
5-
# Options for 'bundle-build'
6-
ifneq ($(origin CHANNELS), undefined)
7-
BUNDLE_CHANNELS := --channels=$(CHANNELS)
8-
endif
9-
ifneq ($(origin DEFAULT_CHANNEL), undefined)
10-
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
1+
# Capture image tag from git branch name
2+
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || true)
3+
ifeq (,$(GIT_BRANCH))
4+
TAG = latest
5+
else ifeq (master, $(GIT_BRANCH))
6+
TAG = latest
7+
else ifeq (HEAD, $(GIT_BRANCH))
8+
TAG = $(shell git describe --abbrev=0 --tags $(shell git rev-list --abbrev-commit --tags --max-count=1) 2> /dev/null || true)
9+
else
10+
TAG = $(GIT_BRANCH)
1111
endif
12-
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
1312

1413
# Image URL to use all building/pushing image targets
15-
IMG ?= controller:latest
14+
IMG ?= netrisai/netris-operator:$(TAG)
1615
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
1716
CRD_OPTIONS ?= "crd:trivialVersions=true"
1817

@@ -53,6 +52,9 @@ deploy: manifests kustomize
5352
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
5453
$(KUSTOMIZE) build config/default | kubectl apply -f -
5554

55+
undeploy:
56+
$(KUSTOMIZE) build config/default | kubectl delete -f -
57+
5658
# Generate manifests e.g. CRD, RBAC etc.
5759
manifests: controller-gen
5860
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
@@ -109,15 +111,30 @@ else
109111
KUSTOMIZE=$(shell which kustomize)
110112
endif
111113

112-
# Generate bundle manifests and metadata, then validate generated files.
113-
.PHONY: bundle
114-
bundle: manifests kustomize
115-
operator-sdk generate kustomize manifests -q
116-
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
117-
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
118-
operator-sdk bundle validate ./bundle
119-
120-
# Build the bundle image.
121-
.PHONY: bundle-build
122-
bundle-build:
123-
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
114+
release: generate fmt vet manifests kustomize
115+
$(KUSTOMIZE) build config/crd > deploy/netris-operator.crds.yaml
116+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
117+
$(KUSTOMIZE) build config/default > deploy/netris-operator.yaml
118+
119+
pip-install-reqs:
120+
pip3 install yq pyyaml
121+
122+
helm: generate fmt vet manifests pip-install-reqs
123+
mkdir -p deploy/charts/netris-operator/crds/
124+
cp config/crd/bases/* deploy/charts/netris-operator/crds/
125+
echo "{{- if .Values.rbac.create -}}" > deploy/charts/netris-operator/templates/rbac.yaml
126+
for i in $(shell yq -y .resources config/rbac/kustomization.yaml | awk {'print $$2'});\
127+
do echo "---" >> deploy/charts/netris-operator/templates/rbac.yaml && \
128+
scripts/rbac-helm-template.py config/rbac/$${i} | yq -y . >> deploy/charts/netris-operator/templates/rbac.yaml;\
129+
done
130+
echo "{{- end }}" >> deploy/charts/netris-operator/templates/rbac.yaml
131+
@{ \
132+
set -e ;\
133+
HELM_CHART_GEN_TMP_DIR=$$(mktemp -d) ;\
134+
git clone [email protected]:netrisai/charts.git --depth 1 $$HELM_CHART_GEN_TMP_DIR ;\
135+
if [[ -z "$${HELM_CHART_REPO_COMMIT_MSG}" ]]; then HELM_CHART_REPO_COMMIT_MSG=Update-$$(date '+%F_%T' -u); fi ;\
136+
cp -r deploy/charts $$HELM_CHART_GEN_TMP_DIR ;\
137+
cd $$HELM_CHART_GEN_TMP_DIR ;\
138+
git add charts && git commit -m $$HELM_CHART_REPO_COMMIT_MSG && git push -u origin main ;\
139+
rm -rf $$HELM_CHART_GEN_TMP_DIR ;\
140+
}

PROJECT

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
domain: netris.ai
22
layout: go.kubebuilder.io/v2
33
projectName: netris-operator
4-
repo: github.com/netrisx/netris-operator
4+
repo: github.com/netrisai/netris-operator
55
resources:
66
- group: k8s
77
kind: VNet
88
version: v1alpha1
9+
- group: k8s
10+
kind: VNetMeta
11+
version: v1alpha1
912
version: 3-alpha
1013
plugins:
1114
go.sdk.operatorframework.io/v2-alpha: {}

api/v1alpha1/vnet_types.go

+25-48
Original file line numberDiff line numberDiff line change
@@ -28,51 +28,6 @@ import (
2828
// Tenant_name string `json:"tenant_name"`
2929
// }
3030

31-
type VNetGateways struct {
32-
Id int `json:"id,omitempty"`
33-
Gateway string `json:"gateway"`
34-
Gw_length string `json:"gw_length"`
35-
Version string `json:"version"`
36-
Va_vlan_id int `json:"va_vlan_id,omitempty"`
37-
}
38-
39-
// type VNetMembers struct {
40-
// Port_id int `json:"port_id"`
41-
// Vlan_id string `json:"vlan_id"`
42-
// Tenant_id int `json:"tenant_id"`
43-
// ChildPort int `json:"childPort"`
44-
// ParentPort int `json:"parentPort"`
45-
// Member_state string `json:"member_state"`
46-
// Lacp string `json:"lacp"`
47-
// Port_name string `json:"port_name"`
48-
// PortIsUntagged bool `json:"portIsUntagged"`
49-
// }
50-
51-
// VNetSpec defines the desired state of VNet
52-
type VNetSpec struct {
53-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
54-
// Important: Run "make" to regenerate code after modifying this file
55-
56-
ID int `json:"id,omitempty"`
57-
Name string `json:"name"`
58-
// +kubebuilder:validation:Minimum=1
59-
Vxlan_id int `json:"vxlan_id,omitempty"`
60-
Mac_address string `json:"mac_address,omitempty"`
61-
MembersCount int `json:"membersCount,omitempty"`
62-
State string `json:"state"`
63-
Provisioning int `json:"provisioning"`
64-
Create_date string `json:"create_date,omitempty"`
65-
Modified_date string `json:"modifiedDate,omitempty"`
66-
Owner int `json:"owner"`
67-
Va_mode bool `json:"va_mode"`
68-
Va_native_vlan int `json:"va_native_vlan"`
69-
Va_vlans string `json:"va_vlans"`
70-
Tenants []int `json:"tenants"`
71-
Sites []int `json:"sites"`
72-
Gateways []VNetGateways `json:"gateways"`
73-
Members string `json:"members"`
74-
}
75-
7631
// VNetStatus defines the observed state of VNet
7732
type VNetStatus struct {
7833
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
@@ -86,11 +41,11 @@ type VNetStatus struct {
8641

8742
// VNet is the Schema for the vnets API
8843
type VNet struct {
44+
// APIVersion string `json:"apiVersion"`
45+
// Kind string `json:"kind"`
8946
metav1.TypeMeta `json:",inline"`
9047
metav1.ObjectMeta `json:"metadata,omitempty"`
91-
92-
Spec VNetSpec `json:"spec"`
93-
Status VNetStatus `json:"status,omitempty"`
48+
Spec VNetSpec `json:"spec"`
9449
}
9550

9651
// +kubebuilder:object:root=true
@@ -102,6 +57,28 @@ type VNetList struct {
10257
Items []VNet `json:"items"`
10358
}
10459

60+
// VNetSpec .
61+
type VNetSpec struct {
62+
Owner string `json:"ownerTenant"`
63+
State string `json:"state,omitempty"`
64+
GuestTenants []string `json:"guestTenants"`
65+
Sites []VNetSite `json:"sites"`
66+
}
67+
68+
// VNetSite .
69+
type VNetSite struct {
70+
Name string `json:"name"`
71+
Gateways []string `json:"gateways,omitempty"`
72+
SwitchPorts []VNetSwitchPort `json:"switchPorts,omitempty"`
73+
}
74+
75+
// VNetSwitchPort .
76+
type VNetSwitchPort struct {
77+
Name string `json:"name"`
78+
VlanID int `json:"vlanId,omitempty"`
79+
State string `json:"state,omitempty"`
80+
}
81+
10582
func init() {
10683
SchemeBuilder.Register(&VNet{}, &VNetList{})
10784
}

0 commit comments

Comments
 (0)