Skip to content

Commit 18bbf29

Browse files
authored
Merge pull request #314 from LionelJouin/operator-merge
Meridio-Operator merged with Merido repository
2 parents 1873d01 + c904052 commit 18bbf29

File tree

194 files changed

+15261
-35
lines changed

Some content is hidden

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

194 files changed

+15261
-35
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore all files which are not go type
3+
!**/*.go
4+
!**/*.mod
5+
!**/*.sum

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616

1717
_output/
1818
bin/
19-
temp/
19+
temp/
20+
testbin/*
21+
22+
# Kubernetes Generated files - skip generated files, except for vendored files
23+
24+
!vendor/**/zz_generated.*

Makefile

+67-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ default:
77
all: default
88

99
help: ## Display this help.
10-
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
10+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
1111

1212
############################################################################
1313
# Variables
1414
############################################################################
1515

16-
IMAGES ?= base-image stateless-lb proxy tapa ipam nsp example-target frontend
16+
IMAGES ?= base-image stateless-lb proxy tapa ipam nsp example-target frontend operator
1717

1818
# Versions
1919
VERSION ?= latest
@@ -25,6 +25,7 @@ VERSION_NSP ?= $(VERSION)
2525
VERSION_EXAMPLE_TARGET ?= $(VERSION)
2626
VERSION_FRONTEND ?= $(VERSION)
2727
VERSION_BASE_IMAGE ?= $(VERSION)
28+
VERSION_OPERATOR ?= $(VERSION)
2829
LOCAL_VERSION ?= $(VERSION)
2930

3031
# E2E tests
@@ -33,7 +34,7 @@ E2E_PARAMETERS ?= $(shell cat ./test/e2e/environment/kind-helm/dualstack/config.
3334
E2E_SEED ?= $(shell shuf -i 1-2147483647 -n1)
3435

3536
# Contrainer Registry
36-
REGISTRY ?= localhost:5000/meridio
37+
REGISTRY ?= registry.nordix.org/cloud-native/meridio
3738
BASE_IMAGE ?= $(REGISTRY)/base-image:$(VERSION_BASE_IMAGE)
3839
DEBUG_IMAGE ?= $(REGISTRY)/debug:$(VERSION)
3940

@@ -45,15 +46,23 @@ MOCKGEN = $(shell pwd)/bin/mockgen
4546
PROTOC_GEN_GO = $(shell pwd)/bin/protoc-gen-go
4647
PROTOC_GEN_GO_GRPC = $(shell pwd)/bin/protoc-gen-go-grpc
4748
NANCY = $(shell pwd)/bin/nancy
49+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
50+
KUSTOMIZE = $(shell pwd)/bin/kustomize
4851
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
4952

5053
BUILD_DIR ?= build
5154
BUILD_STEPS ?= build tag push
5255

56+
# Security Scan
5357
OUTPUT_DIR ?= _output
54-
5558
SECURITY_SCAN_VOLUME ?= --volume /var/run/docker.sock:/var/run/docker.sock --volume $(HOME)/Library/Caches:/root/.cache/
5659

60+
# Operator
61+
TEMPLATES_HELM_CHART_VALUES_PATH = config/templates/charts/meridio/values.yaml
62+
OPERATOR_NAMESPACE = meridio-operator
63+
ENABLE_MUTATING_WEBHOOK?=true
64+
WEBHOOK_SUPPORT ?= spire # spire or certmanager
65+
5766
#############################################################################
5867
# Container: Build, tag, push
5968
#############################################################################
@@ -73,7 +82,7 @@ push:
7382
#############################################################################
7483

7584
.PHONY: base-image
76-
base-image: ## Build the base-image
85+
base-image: ## Build the base-image.
7786
VERSION=$(VERSION_BASE_IMAGE) IMAGE=base-image $(MAKE) -s $(BUILD_STEPS)
7887

7988
.PHONY: debug-image
@@ -101,13 +110,17 @@ nsp: ## Build the nsp.
101110
VERSION=$(VERSION_NSP) IMAGE=nsp $(MAKE) -s $(BUILD_STEPS)
102111

103112
.PHONY: example-target
104-
example-target:
113+
example-target: ## Build the example target.
105114
VERSION=$(VERSION_EXAMPLE_TARGET) BUILD_DIR=examples/target/build IMAGE=example-target $(MAKE) $(BUILD_STEPS)
106115

107116
.PHONY: frontend
108117
frontend: ## Build the frontend.
109118
VERSION=$(VERSION_FRONTEND) IMAGE=frontend $(MAKE) -s $(BUILD_STEPS)
110119

120+
.PHONY: operator
121+
operator: ## Build the operator.
122+
VERSION=$(VERSION_OPERATOR) IMAGE=operator $(MAKE) -s $(BUILD_STEPS)
123+
111124
#############################################################################
112125
##@ Testing & Code check
113126
#############################################################################
@@ -186,6 +199,45 @@ ambassador-proto: proto-compiler
186199
.PHONY: proto
187200
proto: ipam-proto nsp-proto ambassador-proto ## Compile the proto.
188201

202+
.PHONY: manifests
203+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
204+
$(CONTROLLER_GEN) crd rbac:roleName=operator-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
205+
206+
.PHONY: generate-controller
207+
generate-controller: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
208+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
209+
210+
#############################################################################
211+
##@ Operator
212+
#############################################################################
213+
214+
.PHONY: deploy
215+
deploy: manifests kustomize namespace configure-webhook set-templates-values ## Deploy controller to the K8s cluster specified in ~/.kube/config.
216+
cd config/operator && $(KUSTOMIZE) edit set image operator=${REGISTRY}/operator:${VERSION_OPERATOR}
217+
$(KUSTOMIZE) build config/default --enable-helm | kubectl apply -f -
218+
219+
.PHONY: undeploy
220+
undeploy: namespace configure-webhook ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
221+
$(KUSTOMIZE) build config/default --enable-helm | kubectl delete -f - --ignore-not-found=true
222+
223+
.PHONY: set-templates-values
224+
set-templates-values: # Set the values in the templates helm chart
225+
sed -i 's/^version: .*/version: ${VERSION}/' ${TEMPLATES_HELM_CHART_VALUES_PATH} ; \
226+
sed -i 's/^registry: .*/registry: $(shell echo ${REGISTRY} | cut -d "/" -f 1)/' ${TEMPLATES_HELM_CHART_VALUES_PATH} ; \
227+
sed -i 's#^organization: .*#organization: $(shell echo ${REGISTRY} | cut -d "/" -f 2-)#' ${TEMPLATES_HELM_CHART_VALUES_PATH}
228+
229+
.PHONY: namespace
230+
namespace: # Edit the namespace of operator to be deployed
231+
cd config/default && $(KUSTOMIZE) edit set namespace ${OPERATOR_NAMESPACE}
232+
233+
.PHONY: print-manifests
234+
print-manifests: manifests kustomize namespace configure-webhook set-templates-values # Generate manifests to be deployed in the cluster
235+
cd config/operator && $(KUSTOMIZE) edit set image operator=${REGISTRY}/operator:${VERSION_OPERATOR}
236+
$(KUSTOMIZE) build config/default --enable-helm
237+
238+
configure-webhook:
239+
ENABLE_MUTATING_WEBHOOK=$(ENABLE_MUTATING_WEBHOOK) WEBHOOK_SUPPORT=$(WEBHOOK_SUPPORT) hack/webhook-switch.sh
240+
189241
#############################################################################
190242
# Tools
191243
#############################################################################
@@ -227,6 +279,14 @@ ginkgo:
227279
nancy-tool:
228280
$(call go-get-tool,$(NANCY),github.com/sonatype-nexus-community/[email protected])
229281

282+
.PHONY: controller-gen
283+
controller-gen:
284+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
285+
286+
.PHONY: kustomize
287+
kustomize:
288+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
289+
230290
# go-get-tool will 'go get' any package $2 and install it to $1.
231291
define go-get-tool
232292
@[ -f $(1) ] || { \
@@ -238,4 +298,4 @@ echo "Downloading $(2)" ;\
238298
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
239299
rm -rf $$TMP_DIR ;\
240300
}
241-
endef
301+
endef

PROJECT

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
domain: nordix.org
2+
layout:
3+
- go.kubebuilder.io/v3
4+
plugins:
5+
manifests.sdk.operatorframework.io/v2: {}
6+
scorecard.sdk.operatorframework.io/v2: {}
7+
projectName: meridio
8+
repo: github.com/nordix/meridio
9+
resources:
10+
- api:
11+
crdVersion: v1
12+
namespaced: true
13+
controller: true
14+
domain: nordix.org
15+
group: meridio
16+
kind: Trench
17+
path: github.com/nordix/meridio/api/v1alpha1
18+
version: v1alpha1
19+
webhooks:
20+
validation: true
21+
webhookVersion: v1
22+
- api:
23+
crdVersion: v1
24+
namespaced: true
25+
controller: true
26+
domain: nordix.org
27+
group: meridio
28+
kind: Vip
29+
path: github.com/nordix/meridio/api/v1alpha1
30+
version: v1alpha1
31+
webhooks:
32+
validation: true
33+
webhookVersion: v1
34+
- api:
35+
crdVersion: v1
36+
namespaced: true
37+
controller: true
38+
domain: nordix.org
39+
group: meridio
40+
kind: Attractor
41+
path: github.com/nordix/meridio/api/v1alpha1
42+
version: v1alpha1
43+
webhooks:
44+
validation: true
45+
webhookVersion: v1
46+
- api:
47+
crdVersion: v1
48+
namespaced: true
49+
controller: true
50+
domain: nordix.org
51+
group: meridio
52+
kind: Gateway
53+
path: github.com/nordix/meridio/api/v1alpha1
54+
version: v1alpha1
55+
webhooks:
56+
validation: true
57+
webhookVersion: v1
58+
- api:
59+
crdVersion: v1
60+
namespaced: true
61+
controller: true
62+
domain: nordix.org
63+
group: meridio
64+
kind: Conduit
65+
path: github.com/nordix/meridio/api/v1alpha1
66+
version: v1alpha1
67+
webhooks:
68+
validation: true
69+
webhookVersion: v1
70+
- api:
71+
crdVersion: v1
72+
namespaced: true
73+
controller: true
74+
domain: nordix.org
75+
group: meridio
76+
kind: Stream
77+
path: github.com/nordix/meridio/api/v1alpha1
78+
version: v1alpha1
79+
webhooks:
80+
validation: true
81+
webhookVersion: v1
82+
- api:
83+
crdVersion: v1
84+
namespaced: true
85+
controller: true
86+
domain: nordix.org
87+
group: meridio
88+
kind: Flow
89+
path: github.com/nordix/meridio/api/v1alpha1
90+
version: v1alpha1
91+
webhooks:
92+
validation: true
93+
webhookVersion: v1
94+
version: "3"

api/v1alpha1/attractor_types.go

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
Copyright (c) 2021-2022 Nordix Foundation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime/schema"
22+
)
23+
24+
// AttractorSpec defines the desired state of Attractor
25+
type AttractorSpec struct {
26+
// +kubebuilder:default=1
27+
28+
// The number of front-end pods. (The load-balancer is bundled with front-end currently)
29+
// +optional
30+
Replicas *int32 `json:"replicas,omitempty"`
31+
32+
// Reference to the composite conduits
33+
Composites []string `json:"composites"`
34+
35+
// gateways that attractor expect to use
36+
// +optional
37+
Gateways []string `json:"gateways,omitempty"`
38+
39+
// vips that attractor will announce to the gateways when possible
40+
// +optional
41+
Vips []string `json:"vips,omitempty"`
42+
43+
// defines the interface information that attractor use
44+
Interface InterfaceSpec `json:"interface"`
45+
}
46+
47+
type InterfaceSpec struct {
48+
// name of the interface
49+
Name string `json:"name"`
50+
51+
// (immutable) ipv4 prefix of the interface, which is used for frontend to set up communication with the ipv4 gateways
52+
PrefixIPv4 string `json:"ipv4-prefix"`
53+
54+
// (immutable) ipv6 prefix of the interface, which is used for frontend to set up communication with the ipv6 gateways
55+
PrefixIPv6 string `json:"ipv6-prefix"`
56+
57+
// interface choice.
58+
// +kubebuilder:default=nsm-vlan
59+
// +kubebuilder:validation:Enum=nsm-vlan
60+
Type string `json:"type,omitempty"`
61+
62+
// if the type is "nsm-vlan", this information must be specified
63+
NSMVlan NSMVlanSpec `json:"nsm-vlan,omitempty"`
64+
}
65+
66+
type NSMVlanSpec struct {
67+
// (immutable) master interface of the vlan interface to be used for external connectivity
68+
BaseInterface string `json:"base-interface,omitempty"`
69+
70+
// (immutable) vlan ID of the vlan interface to be used for external connectivity
71+
VlanID *int32 `json:"vlan-id,omitempty"`
72+
}
73+
74+
// AttractorStatus defines the observed state of Attractor
75+
type AttractorStatus struct {
76+
}
77+
78+
//+kubebuilder:object:root=true
79+
//+kubebuilder:subresource:status
80+
//+kubebuilder:printcolumn:name="Interface-Name",type=string,JSONPath=`.spec.interface.name`
81+
//+kubebuilder:printcolumn:name="Interface-Type",type=string,JSONPath=`.spec.interface.type`
82+
//+kubebuilder:printcolumn:name="Gateways",type=string,JSONPath=`.spec.gateways`
83+
//+kubebuilder:printcolumn:name="Vips",type=string,JSONPath=`.spec.vips`
84+
//+kubebuilder:printcolumn:name="Composites",type=string,JSONPath=`.spec.composites`
85+
//+kubebuilder:printcolumn:name="Replicas",type=string,JSONPath=`.spec.replicas`
86+
//+kubebuilder:printcolumn:name="Trench",type=string,JSONPath=`.metadata.labels.trench`
87+
88+
// Attractor is the Schema for the attractors API. It defines how traffic are
89+
// attracted and lead into the K8s cluster. This includes which external interface
90+
// to consume. The Attractor is instantiated as a set of pods running frontend
91+
// functionality.
92+
type Attractor struct {
93+
metav1.TypeMeta `json:",inline"`
94+
metav1.ObjectMeta `json:"metadata,omitempty"`
95+
96+
Spec AttractorSpec `json:"spec,omitempty"`
97+
Status AttractorStatus `json:"status,omitempty"`
98+
}
99+
100+
//+kubebuilder:object:root=true
101+
102+
// AttractorList contains a list of Attractor
103+
type AttractorList struct {
104+
metav1.TypeMeta `json:",inline"`
105+
metav1.ListMeta `json:"metadata,omitempty"`
106+
Items []Attractor `json:"items"`
107+
}
108+
109+
func init() {
110+
SchemeBuilder.Register(&Attractor{}, &AttractorList{})
111+
}
112+
113+
func (r *Attractor) GroupResource() schema.GroupResource {
114+
return schema.GroupResource{
115+
Group: r.GroupVersionKind().Group,
116+
Resource: r.GroupVersionKind().Kind,
117+
}
118+
}
119+
120+
func (r *Attractor) GroupKind() schema.GroupKind {
121+
return schema.GroupKind{
122+
Group: r.GroupVersionKind().Group,
123+
Kind: r.GroupVersionKind().Kind,
124+
}
125+
}

0 commit comments

Comments
 (0)