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

Gradual rollout #110

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,19 @@ COPY go.sum go.sum
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Build router
RUN apk add llvm clang linux-headers libbpf-dev musl-dev

# Copy the go source
COPY cmd/manager/main.go main.go
COPY cmd/operator/main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/

# Build router
COPY bpf/ bpf/
RUN cd pkg/bpf/ && go generate

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o operator main.go

FROM alpine:latest

RUN apk add --no-cache iptables ip6tables

WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/operator .
USER 65532:65532

ENTRYPOINT ["/manager"]
ENTRYPOINT ["/operator"]
49 changes: 39 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/telekom/das-schiff-network-operator:latest
# Agent image URL to use all building/pushing image targets
AGENT_IMG ?= ghcr.io/telekom/das-schiff-network-operator-agent:latest
# Sidecar image URL to use all building/pushing image targets
SIDECAR_IMG ?= ghcr.io/telekom/frr-exporter:latest
# Operator image URL to use all building/pushing image targets
OPERATOR_IMG ?= ghcr.io/telekom/das-schiff-network-opeator:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25

Expand Down Expand Up @@ -68,33 +70,59 @@ test: manifests generate fmt vet envtest ## Run tests.
##@ Build

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/manager/main.go
build: generate fmt vet ## Build agent binary.
go build -o bin/operator cmd/operator/main.go
go build -o bin/agent cmd/agent/main.go
go build -o bin/frr-exporter cmd/frr-exporter/main.go

.PHONY: operator-build
operator-build: generate fmt vet ## Build agent binary.
go build -o bin/operator cmd/operator/main.go

.PHONY: agent-build
agent-build: generate fmt vet ## Build agent binary.
go build -o bin/agent cmd/agent/main.go

.PHONY: sidecar-build
sidecar-build: build
go build -o bin/frr-exporter cmd/frr-exporter/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/manager/main.go
go run ./cmd/agent/main.go

.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .
docker build -t ${OPERATOR_IMG} .
docker build -t ${AGENT_IMG} -f agent.Dockerfile .
docker build -t ${SIDECAR_IMG} -f frr-exporter.Dockerfile .

.PHONY: docker-build-agent
docker-build-agent: test ## Build docker image with the manager.
docker build -t ${AGENT_IMG} -f agent.Dockerfile .

.PHONY: docker-build-sidecar
docker-build-sidecar: test ## Build docker image with the manager.
docker build -t ${SIDECAR_IMG} -f frr-exporter.Dockerfile .

.PHONY: docker-build-operator
docker-build-operator: test ## Build docker image with the manager.
docker build -t ${OPERATOR_IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
docker-push: docker-push-agent docker-push-sidecar docker-push-operator

.PHONY: docker-push-agent
docker-push-agent: ## Push docker image with the manager.
docker push ${AGENT_IMG}

.PHONY: docker-push-sidecar
docker-push-sidecar: ## Push docker image with the manager.
docker push ${SIDECAR_IMG}

.PHONY: docker-push-operator
docker-push-operator: ## Push docker image with the manager.
docker push ${OPERATOR_IMG}

##@ Release

Expand Down Expand Up @@ -133,8 +161,9 @@ uninstall-certs: manifests kustomize ## Uninstall certs

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image frr-exporter=${SIDECAR_IMG}
cd config/agent && $(KUSTOMIZE) edit set image agent=${AGENT_IMG}
cd config/agent && $(KUSTOMIZE) edit set image frr-exporter=${SIDECAR_IMG}
cd config/operator && $(KUSTOMIZE) edit set image operator=${OPERATOR_IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

.PHONY: undeploy
Expand Down
37 changes: 37 additions & 0 deletions agent.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build the manager binary
FROM docker.io/library/golang:1.21-alpine as builder


WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Build router
RUN apk add llvm clang linux-headers libbpf-dev musl-dev

# Copy the go source
COPY cmd/agent/main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/

# Build router
COPY bpf/ bpf/
RUN cd pkg/bpf/ && go generate

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o agent main.go

FROM alpine:latest

RUN apk add --no-cache iptables ip6tables

WORKDIR /
COPY --from=builder /workspace/agent .
USER 65532:65532

ENTRYPOINT ["/agent"]
87 changes: 87 additions & 0 deletions api/v1alpha1/networkconfigrevision_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2024.

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 v1alpha1

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"

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

// NetworkConfigSpec defines the desired state of NetworkConfig.
type NetworkConfigRevisionSpec struct {
Config NodeNetworkConfigSpec `json:"config"`
Revision string `json:"revision"`
}

type NetworkConfigRevisionStatus struct {
IsInvalid bool `json:"isInvalid"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=ncr,scope=Cluster
//+kubebuilder:printcolumn:name="Invalid",type=string,JSONPath=`.status.isInvalid`
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// NetworkConfig is the Schema for the node configuration.
type NetworkConfigRevision struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NetworkConfigRevisionSpec `json:"spec,omitempty"`
Status NetworkConfigRevisionStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&NetworkConfigRevision{}, &NetworkConfigRevisionList{})
}

func NewRevision(config *NodeNetworkConfig) (*NetworkConfigRevision, error) {
data, err := json.Marshal(config.Spec)
if err != nil {
return nil, fmt.Errorf("error marshalling data: %w", err)
}

h := sha256.New()
if _, err := h.Write(data); err != nil {
return nil, fmt.Errorf("error writing MD5 data: %w", err)
}
hash := h.Sum(nil)
hashHex := hex.EncodeToString(hash)

return &NetworkConfigRevision{
ObjectMeta: metav1.ObjectMeta{Name: hashHex[:10]},
Spec: NetworkConfigRevisionSpec{
Config: config.Spec,
Revision: hashHex,
},
Status: NetworkConfigRevisionStatus{},
}, nil
}
82 changes: 82 additions & 0 deletions api/v1alpha1/nodenetworkconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 2024.

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 v1alpha1

import (
"reflect"

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

// NodeNetworkConfigSpec defines the desired state of NodeConfig.
type NodeNetworkConfigSpec struct {
Revision string `json:"revision"`
Layer2 []Layer2NetworkConfigurationSpec `json:"layer2"`
Vrf []VRFRouteConfigurationSpec `json:"vrf"`
RoutingTable []RoutingTableSpec `json:"routingTable"`
}

// NodeNetworkConfigStatus defines the observed state of NodeConfig.
type NodeNetworkConfigStatus struct {
ConfigStatus string `json:"configStatus"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=nnc,scope=Cluster
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.configStatus`
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// NodeNetworkConfig is the Schema for the node configuration.
type NodeNetworkConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NodeNetworkConfigSpec `json:"spec,omitempty"`
Status NodeNetworkConfigStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func (nc *NodeNetworkConfig) IsEqual(c *NodeNetworkConfig) bool {
return reflect.DeepEqual(nc.Spec.Layer2, c.Spec.Layer2) && reflect.DeepEqual(nc.Spec.Vrf, c.Spec.Vrf) && reflect.DeepEqual(nc.Spec.RoutingTable, c.Spec.RoutingTable)
}

func NewEmptyConfig(name string) *NodeNetworkConfig {
return &NodeNetworkConfig{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: NodeNetworkConfigSpec{
Vrf: []VRFRouteConfigurationSpec{},
Layer2: []Layer2NetworkConfigurationSpec{},
RoutingTable: []RoutingTableSpec{},
},
Status: NodeNetworkConfigStatus{
ConfigStatus: "",
},
}
}

func init() {
SchemeBuilder.Register(&NodeNetworkConfig{}, &NodeNetworkConfigList{})
}
Loading