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 1 commit 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
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM docker.io/library/golang:1.21-alpine as builder
FROM docker.io/library/golang:1.21-alpine AS builder


WORKDIR /workspace
Expand All @@ -14,7 +14,7 @@ RUN go mod download
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/
Expand All @@ -25,14 +25,14 @@ RUN cd pkg/bpf/ && go generate

ARG ldflags
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "${ldflags}" -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "${ldflags}" -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"]
53 changes: 41 additions & 12 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 @@ -41,7 +43,7 @@ all: build
help: ## Display this help.
@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)

##@ DevelopmentLDFLAGS := $(shell hack/version.sh)
##@ Development

.PHONY: bpf-generate
bpf-generate: ## Run go generate for the BPF program (builds it as well)
Expand Down Expand Up @@ -70,33 +72,59 @@ test: manifests generate fmt vet envtest ## Run tests.
##@ Build

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -ldflags "$(LDFLAGS)" -o bin/manager cmd/manager/main.go
build: generate fmt vet ## Build agent binary.
go build -ldflags "$(LDFLAGS)" -o bin/operator cmd/operator/main.go
go build -ldflags "$(LDFLAGS)" -o bin/agent cmd/agent/main.go
go build -ldflags "$(LDFLAGS)" -o bin/frr-exporter cmd/frr-exporter/main.go

.PHONY: operator-build
operator-build: generate fmt vet ## Build agent binary.
go build -ldflags "$(LDFLAGS)" -o bin/operator cmd/operator/main.go

.PHONY: agent-build
agent-build: generate fmt vet ## Build agent binary.
go build -ldflags "$(LDFLAGS)" -o bin/agent cmd/agent/main.go

.PHONY: sidecar-build
sidecar-build: build
go build -ldflags "$(LDFLAGS)" -o bin/frr-exporter cmd/frr-exporter/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run -ldflags "$(LDFLAGS)" ./cmd/manager/main.go
go run -ldflags "$(LDFLAGS)" ./cmd/agent/main.go

.PHONY: docker-build
docker-build: #test ## Build docker image with the manager.
docker build --build-arg ldflags="$(LDFLAGS)" -t ${IMG} .
docker-build: test ## Build docker image with the manager.
docker build --build-arg ldflags="$(LDFLAGS)" -t ${OPERATOR_IMG} .
docker build --build-arg ldflags="$(LDFLAGS)" -t ${AGENT_IMG} -f agent.Dockerfile .
docker build --build-arg ldflags="$(LDFLAGS)" -t ${SIDECAR_IMG} -f frr-exporter.Dockerfile .

.PHONY: docker-build-agent
docker-build-agent: test ## Build docker image with the manager.
docker build --build-arg ldflags="$(LDFLAGS)" -t ${AGENT_IMG} -f agent.Dockerfile .

.PHONY: docker-build-sidecar
docker-build-sidecar: test ## Build docker image with the manager.
docker build --build-arg ldflags="$(LDFLAGS)" -t ${SIDECAR_IMG} -f frr-exporter.Dockerfile .

.PHONY: docker-build-operator
docker-build-operator: test ## Build docker image with the manager.
docker build --build-arg ldflags="$(LDFLAGS)" -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 @@ -135,8 +163,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"]
102 changes: 102 additions & 0 deletions api/v1alpha1/networkconfigrevision_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
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 stores global configuration of the nodes.
Config NodeNetworkConfigSpec `json:"config"`
// Revision is a hash of the NetworkConfigRevision object that is used to identify the particular revision.
Revision string `json:"revision"`
}

type NetworkConfigRevisionStatus struct {
// IsInvalid determines if NetworkConfigRevision results in misconfigured nodes (invalid configuration).
IsInvalid bool `json:"isInvalid"`
// Ready informs about how many nodes were already provisioned with a config derived from the revision.
Ready int `json:"ready"`
// Ongoing informs about how many nodes are currently provisioned with a config derived from the revision.
Ongoing int `json:"ongoing"`
// Queued informs about how many nodes are currently waiting to be provisiined with a config derived from the revision.
Queued int `json:"queued"`
// Total informs about how many nodes in total can be provisiined with a config derived from the revision.
Total int `json:"total"`
}

//+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="Queued",type="integer",JSONPath=".status.queued"
//+kubebuilder:printcolumn:name="Ongoing",type="integer",JSONPath=".status.ongoing"
//+kubebuilder:printcolumn:name="Ready",type="integer",JSONPath=".status.ready"
//+kubebuilder:printcolumn:name="Total",type="integer",JSONPath=".status.total"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

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

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

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("failed hashing network config: %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
}

func init() {
SchemeBuilder.Register(&NetworkConfigRevision{}, &NetworkConfigRevisionList{})
}
80 changes: 80 additions & 0 deletions api/v1alpha1/nodenetworkconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NodeNetworkConfigSpec defines the desired state of NodeConfig.
type NodeNetworkConfigSpec struct {
// Revision stores hash of the NodeConfigRevision that was used to create the NodeNetworkConfig object.
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 describes provisioning state od the NodeConfig. Can be either 'provisioning' or 'provisioned'.
ConfigStatus string `json:"configStatus"`
// LastUpdate determines when last update (change) of the ConfigStatus field took place.
LastUpdate metav1.Time `json:"lastUpdate"`
}

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