Skip to content

Commit

Permalink
Initial bootstrap (#12)
Browse files Browse the repository at this point in the history
* Bootstrap

Signed-off-by: Hao Hao <[email protected]>

* new: added PipelineRollout CRD and controller.

Signed-off-by: Antonino Fugazzotto <[email protected]>

* using RawExtension type for pipeline (we may need to use the numaflow PipelineSpec though)

Signed-off-by: Antonino Fugazzotto <[email protected]>

* Update `Makefile`

Signed-off-by: Hao Hao <[email protected]>

* Add logger and config

Signed-off-by: Hao Hao <[email protected]>

* added PipelineRollout controller to main.

Signed-off-by: Antonino Fugazzotto <[email protected]>

* Cherry-pick gitops-engine version upgrade (#304)

Signed-off-by: Hao Hao <[email protected]>

* Added NumaflowControllerRollout and ISBServiceRollout CRDs and Controllers (#302)

Signed-off-by: Antonino Fugazzotto <[email protected]>

* chore: fix broken unit tests for new controllers (#305)

Signed-off-by: Antonino Fugazzotto <[email protected]>

* Update spec (#306)

Signed-off-by: Julie Vogelman <[email protected]>

* Apply update to all controllers (#309)

Signed-off-by: Antonino Fugazzotto <[email protected]>

* fix: panics in controller-runtime (#311)

Signed-off-by: Julie Vogelman <[email protected]>

* Update existing CR if it already exists (#308)

Signed-off-by: Julie Vogelman <[email protected]>

* Add configmap to store numaflow controller spec (#307)

Signed-off-by: Hao Hao <[email protected]>

* Pipeline Controller and ISBService Controller reconciliation logic (#312)

Signed-off-by: Julie Vogelman <[email protected]>

* Add generic Status to all controllers (#313)

Signed-off-by: Antonino Fugazzotto <[email protected]>

* feat: reduce the number of reconciliations (#315)

Signed-off-by: Julie Vogelman <[email protected]>

* Print column phase (#316)

Signed-off-by: Antonino Fugazzotto <[email protected]>

* Apply NumaflowController Spec (#314)

Signed-off-by: Hao Hao <[email protected]>

* fix: only `numaflow-controller-definitions-config` should be immutable (#317)

Signed-off-by: Hao Hao <[email protected]>

* fix: update install.yaml (#318)

Signed-off-by: Hao Hao <[email protected]>

* Watch child resources and propagate status back - Pipelines and ISBServices (#319)

Signed-off-by: Julie Vogelman <[email protected]>

* Add OwnerReference to Numaflow controller (#320)

Signed-off-by: Hao Hao <[email protected]>

* Fixed some broken UTs. Adjustments are needed to improve UTs. (#321)

Signed-off-by: Antonino Fugazzotto <[email protected]>

* Add github ci

Signed-off-by: Hao Hao <[email protected]>

---------

Signed-off-by: Hao Hao <[email protected]>
Signed-off-by: Antonino Fugazzotto <[email protected]>
Signed-off-by: Julie Vogelman <[email protected]>
Co-authored-by: Antonino Fugazzotto <[email protected]>
Co-authored-by: Antonino Fugazzotto <[email protected]>
Co-authored-by: Julie Vogelman <[email protected]>
  • Loading branch information
4 people authored May 29, 2024
1 parent 10ec202 commit c6f214c
Show file tree
Hide file tree
Showing 81 changed files with 9,368 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
38 changes: 38 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

name: test
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
jobs:
codegen:
name: Codegen
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Restore go build cache
uses: actions/cache@v3
with:
path: ~/.cache/go-build
key: ${{ runner.os }}-go-build-v1-${{ hashFiles('**/go.mod') }}
- name: Setup Golang
uses: actions/[email protected]
with:
go-version: '1.21'
- name: Add bins to PATH
run: |
echo /home/runner/go/bin >> $GITHUB_PATH
echo /usr/local/bin >> $GITHUB_PATH
- name: Get dependencies
run: go mod download
- name: Make codegen
run: |
echo 'GOPATH=/home/runner/go' >> $GITHUB_ENV
make -B codegen
- name: Ensure nothing changed
run: git diff --exit-code
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dll
*.so
*.dylib
bin/*

# Test binary, built with `go test -c`
*.test
Expand All @@ -19,3 +20,5 @@

# Go workspace file
go.work

config/crd/bases/_.yaml
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Build the manager binary
FROM golang:1.21 as builder
ARG TARGETOS
ARG TARGETARCH
ARG KUSTOMIZE_VERSION="v5.3.0"
ARG HELM_VERSION="v3.13.2"

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

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY pkg/ pkg/
COPY internal/ internal/

# Add a go build cache. The persistent cache helps speed up build steps,
# especially steps that involve installing packages using a package manager.
ENV GOCACHE=/root/.cache/go-build
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN --mount=type=cache,target="/root/.cache/go-build" CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o manager cmd/main.go

# Download kustomize binary
RUN curl --retry 3 --silent --location --remote-name \
"https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz" && \
tar -C /tmp -xf kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz && \
install -m 0755 /tmp/kustomize /usr/local/bin/kustomize

RUN curl --retry 3 --silent --location --remote-name https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz && \
mkdir -p /tmp/helm && tar -C /tmp/helm -xf helm-${HELM_VERSION}-linux-amd64.tar.gz && \
install -m 0755 /tmp/helm/linux-amd64/helm /usr/local/bin/helm

# Use alpine as minimal base image to package the manager binary
FROM alpine
WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /usr/local/bin/kustomize /usr/local/bin/kustomize
COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm

RUN apk add --no-cache git

ENTRYPOINT ["/manager"]
248 changes: 248 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

# Image URL to use all building/pushing image targets
IMG ?= numaplane-controller
VERSION ?= latest
# BASE_VERSION will be used during release process to bump up versions
BASE_VERSION := latest
# Default cluster name where numaplane get deployed, update it as needed.
CLUSTER_NAME ?= staging-usw2-k8s
IMAGE_NAMESPACE ?= quay.io/numaproj
IMAGE_FULL_PATH ?= $(IMAGE_NAMESPACE)/$(IMG):$(VERSION)


BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_BRANCH=$(shell git rev-parse --symbolic-full-name --verify --quiet --abbrev-ref HEAD)
GIT_TAG=$(shell if [[ -z "`git status --porcelain`" ]]; then git describe --exact-match --tags HEAD 2>/dev/null; fi)
GIT_TREE_STATE=$(shell if [[ -z "`git status --porcelain`" ]]; then echo "clean" ; else echo "dirty"; fi)

NUMAFLOW_CRDS=$(shell kubectl get crd | grep -c 'numaflow.numaproj.io')

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUBECTL ?= kubectl
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.14.0

GCFLAGS="all=-N -l"

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

CURRENT_CONTEXT := $(shell [[ "`command -v kubectl`" != '' ]] && kubectl config current-context 2> /dev/null || echo "unset")
IMAGE_IMPORT_CMD := $(shell [[ "`command -v k3d`" != '' ]] && [[ "$(CURRENT_CONTEXT)" =~ k3d-* ]] && echo "k3d image import -c `echo $(CURRENT_CONTEXT) | cut -c 5-`")
ifndef IMAGE_IMPORT_CMD
IMAGE_IMPORT_CMD := $(shell [[ "`command -v minikube`" != '' ]] && [[ "$(CURRENT_CONTEXT)" =~ minikube* ]] && echo "minikube image load")
endif
ifndef IMAGE_IMPORT_CMD
IMAGE_IMPORT_CMD := $(shell [[ "`command -v kind`" != '' ]] && [[ "$(CURRENT_CONTEXT)" =~ kind-* ]] && echo "kind load docker-image")
endif

# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker
CONTAINER_TOOL:=$(shell command -v docker 2> /dev/null)
ifndef CONTAINER_TOOL
CONTAINER_TOOL:=$(shell command -v podman 2> /dev/null)
endif

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

##@ Development

.PHONY: help
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)

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=config/crd/bases
$(KUBECTL) kustomize config/default > config/install.yaml

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: codegen
codegen: generate manifests
./hack/update-codegen.sh
rm -rf ./vendor
go mod tidy

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -race -v ./... -coverprofile cover.out

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.54.2
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
}

.PHONY: lint
lint: generate golangci-lint ## Run golangci-lint linter & yamllint
$(GOLANGCI_LINT) run

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix

##@ Build

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -gcflags=${GCFLAGS} -o bin/manager cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run -gcflags=${GCFLAGS} ./cmd/main.go

.PHONY: run-agent
run-agent: generate fmt vet ## Run agent from your host.
go run -gcflags=${GCFLAGS} cmd/agent/main.go


clean:
-rm bin/manager -f

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: image
image: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${IMAGE_FULL_PATH} .
ifdef IMAGE_IMPORT_CMD
$(IMAGE_IMPORT_CMD) ${IMAGE_FULL_PATH}
endif

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
$(CONTAINER_TOOL) push ${IMAGE_FULL_PATH}

# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
# architectures. (i.e. make docker-buildx IMAGE_FULL_PATH=myregistry/mypoperator:0.0.1). To use this option you need to:
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMAGE_FULL_PATH=<myregistry/image:<tag>> then the export will fail)
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
$(CONTAINER_TOOL) buildx use project-v3-builder
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMAGE_FULL_PATH} -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx rm project-v3-builder
rm Dockerfile.cross

##@ Deployment

ifndef ignore-not-found
ignore-not-found = false
endif

.PHONY: start
start: image
$(KUBECTL) apply -f tests/manifests/numaplane-ns.yaml
$(KUBECTL) kustomize tests/manifests | sed 's/CLUSTER_NAME_VALUE/$(CLUSTER_NAME)/g' | sed '[email protected]/numaproj/@$(IMAGE_NAMESPACE)/@' | sed 's/$(IMG):$(BASE_VERSION)/$(IMG):$(VERSION)/' | $(KUBECTL) apply -f -

##@ Build Dependencies

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

numaflow-crd:
ifeq ($(NUMAFLOW_CRDS), 0)
$(KUBECTL) apply -f https://raw.githubusercontent.com/numaproj/helm-charts/main/charts/numaflow/crds/isbsvcs.yaml
$(KUBECTL) apply -f https://raw.githubusercontent.com/numaproj/helm-charts/main/charts/numaflow/crds/pipelines.yaml
$(KUBECTL) apply -f https://raw.githubusercontent.com/numaproj/helm-charts/main/charts/numaflow/crds/vertices.yaml
endif


# release - targets only available on release branch
ifneq ($(findstring release-,$(GIT_BRANCH)),)

.PHONY: prepare-release
prepare-release: check-version-warning clean update-manifests-version codegen
git status
@git diff --quiet || echo "\n\nPlease run 'git diff' to confirm the file changes are correct.\n"


.PHONY: release
release: check-version-warning
@echo
@echo "1. Make sure you have run 'VERSION=$(VERSION) make prepare-release', and confirmed all the changes are expected."
@echo
@echo "2. Run following commands to commit the changes to the release branch, add give a tag."
@echo
@echo "git commit -am \"Update manifests to $(VERSION)\""
@echo "git push {your-remote}"
@echo
@echo "git tag -a $(VERSION) -m $(VERSION)"
@echo "git push {your-remote} $(VERSION)"
@echo

endif

.PHONY: check-version-warning
check-version-warning:
@if [[ ! "$(VERSION)" =~ ^v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then echo -n "It looks like you're not using a version format like 'v1.2.3', or 'v1.2.3-rc2', that version format is required for our releases. Do you wish to continue anyway? [y/N]" && read ans && [[ $${ans:-N} = y ]]; fi


.PHONY: update-manifests-version
update-manifests-version:
cat config/manager/kustomization.yaml | sed 's/newTag: .*/newTag: $(VERSION)/' > /tmp/base_kustomization.yaml
mv /tmp/base_kustomization.yaml config/manager/kustomization.yaml
38 changes: 38 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: github.com.numaproj
layout:
- go.kubebuilder.io/v4
projectName: numaplane
repo: github.com/numaproj/numaplane
resources:
- api:
crdVersion: v1alpha1
namespaced: true
controller: true
domain: github.com.numaproj
group: numaplane.numaproj.io
kind: PipelineRollout
path: github.com/numaproj/numaplane/pkg/apis/numaplane/v1alpha1
version: v1alpha1
- api:
crdVersion: v1alpha1
namespaced: true
controller: true
domain: github.com.numaproj
group: numaplane.numaproj.io
kind: NumaflowControllerRollout
path: github.com/numaproj/numaplane/pkg/apis/numaplane/v1alpha1
version: v1alpha1
- api:
crdVersion: v1alpha1
namespaced: true
controller: true
domain: github.com.numaproj
group: numaplane.numaproj.io
kind: ISBServiceRollout
path: github.com/numaproj/numaplane/pkg/apis/numaplane/v1alpha1
version: v1alpha1
version: "3"
Loading

0 comments on commit c6f214c

Please sign in to comment.