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

Implement velero installation #7

Merged
merged 4 commits into from
Mar 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # tag=v3.5.0
with:
go-version: '1.21'
go-version: '^1.22'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # tag=v3.3.0
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ jobs:
- ""
steps:
- uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # tag=v3.4.0
- name: Calculate go version
id: vars
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # tag=v3.5.0
with:
go-version: ${{ steps.vars.outputs.go_version }}
go-version: '^1.22'
- name: golangci-lint
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # tag=v3.4.0
with:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ on:

permissions:
contents: write # Allow to create a release.
packages: write

jobs:
build:
name: create draft release
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io/${{ github.actor }}
steps:
- name: Set env
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
Expand All @@ -24,6 +27,20 @@ jobs:
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # tag=v3.5.0
with:
go-version: '^1.22'
- name: Docker login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Convert actor name to lowercase and store in the env
run: |
echo "OWNER=$(echo $GITHUB_ACTOR | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "REGISTRY=$(echo $REGISTRY | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build docker image
run: make docker-build
- name: Push docker image
run: make docker-push
- name: generate release artifacts
run: |
make release
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ _artifacts
tmp/

# Secret files
credentials-velero
credentials-velero

# Release generated
out
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.21 AS builder
FROM golang:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
35 changes: 20 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ OBSERVABILITY_DIR := hack/observability
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)

# Set --output-base for conversion-gen if we are not within GOPATH
ifneq ($(abspath $(ROOT_DIR)),$(shell go env GOPATH)/src/sigs.k8s.io/cluster-api-addon-provider-helm)
ifneq ($(abspath $(ROOT_DIR)),$(shell go env GOPATH)/src/sigs.k8s.io/cluster-api-addon-provider-velero)
CONVERSION_GEN_OUTPUT_BASE := --output-base=$(ROOT_DIR)
else
export GOPATH := $(shell go env GOPATH)
Expand Down Expand Up @@ -187,14 +187,15 @@ GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN))

# Define Docker related variables. Releases should modify and double check these vars.
REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
# REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
REGISTRY ?= ghcr.io/danil-grigorev
PROD_REGISTRY ?= registry.k8s.io/cluster-api-helm

STAGING_REGISTRY ?= gcr.io/k8s-staging-cluster-api-helm
STAGING_BUCKET ?= artifacts.k8s-staging-cluster-api-helm.appspot.com
STAGING_REGISTRY ?= gcr.io/k8s-staging-cluster-api-velero
STAGING_BUCKET ?= artifacts.k8s-staging-cluster-api-velero.appspot.com

# core
IMAGE_NAME ?= cluster-api-helm-controller
IMAGE_NAME ?= cluster-api-velero-controller
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)

# kind
Expand Down Expand Up @@ -358,6 +359,10 @@ verify-container-images: ## Verify container images

##@ build:

.PHONY: run
run: generate ## Run a controller from your host.
go run ./cmd/main.go

.PHONY: manager
manager: ## Build the manager binary into the ./bin folder
go build -trimpath -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/manager .
Expand Down Expand Up @@ -489,11 +494,11 @@ PREVIOUS_TAG ?= $(shell git tag -l | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$$" | sort
RELEASE_ALIAS_TAG := $(PULL_BASE_REF)
RELEASE_DIR := out
RELEASE_NOTES_DIR := _releasenotes
GIT_REPO_NAME ?= cluster-api-addon-provider-helm
GIT_REPO_NAME ?= cluster-api-addon-provider-velero
GIT_ORG_NAME ?= kubernetes-sigs
USER_FORK ?= $(shell git config --get remote.origin.url | cut -d/ -f4) # only works on https://github.com/<username>/cluster-api-addon-provider-helm.git style URLs
USER_FORK ?= $(shell git config --get remote.origin.url | cut -d/ -f4) # only works on https://github.com/<username>/cluster-api-addon-provider-velero.git style URLs
ifdef USER_FORK
USER_FORK := $(shell git config --get remote.origin.url | cut -d: -f2 | cut -d/ -f1) # for git@github.com:<username>/cluster-api-addon-provider-helm.git style URLs
USER_FORK := $(shell git config --get remote.origin.url | cut -d: -f2 | cut -d/ -f1) # for git@github.com:<username>/cluster-api-addon-provider-velero.git style URLs
endif
IMAGE_REVIEWERS ?= $(shell ./hack/get-project-maintainers.sh)

Expand Down Expand Up @@ -557,15 +562,15 @@ release-staging: ## Build and push container images to the staging bucket
REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag

.PHONY: release-staging-nightly
release-staging-nightly: ## Tag and push container images to the staging bucket. Example image tag: cluster-api-helm-controller:nightly_main_20210121
release-staging-nightly: ## Tag and push container images to the staging bucket. Example image tag: cluster-api-velero-controller:nightly_main_20210121
$(eval NEW_RELEASE_ALIAS_TAG := nightly_$(RELEASE_ALIAS_TAG)_$(shell date +'%Y%m%d'))
echo $(NEW_RELEASE_ALIAS_TAG)
$(MAKE) release-alias-tag TAG=$(RELEASE_ALIAS_TAG) RELEASE_ALIAS_TAG=$(NEW_RELEASE_ALIAS_TAG)
# Set the manifest image to the staging bucket.
$(MAKE) manifest-modification REGISTRY=$(STAGING_REGISTRY) RELEASE_TAG=$(NEW_RELEASE_ALIAS_TAG)
## Build the manifests
$(MAKE) release-manifests
# Example manifest location: artifacts.k8s-staging-cluster-api-helm.appspot.com/components/nightly_main_20210121/bootstrap-components.yaml
# Example manifest location: artifacts.k8s-staging-cluster-api-velero.appspot.com/components/nightly_main_20210121/bootstrap-components.yaml
gsutil cp $(RELEASE_DIR)/* gs://$(STAGING_BUCKET)/components/$(NEW_RELEASE_ALIAS_TAG)

.PHONY: release-alias-tag
Expand All @@ -575,7 +580,7 @@ release-alias-tag: ## Add the release alias tag to the last build tag
.PHONY: release-notes
release-notes: $(RELEASE_NOTES_DIR) $(RELEASE_NOTES)
@if [ -n "${PRE_RELEASE}" ]; then \
echo ":rotating_light: This is a RELEASE CANDIDATE. Use it only for testing purposes. If you find any bugs, file an [issue](https://github.com/kubernetes-sigs/cluster-api-addon-provider-helm/issues/new)." > $(RELEASE_NOTES_DIR)/release-notes-$(RELEASE_TAG).md; \
echo ":rotating_light: This is a RELEASE CANDIDATE. Use it only for testing purposes. If you find any bugs, file an [issue](https://github.com/kubernetes-sigs/cluster-api-addon-provider-velero/issues/new)." > $(RELEASE_NOTES_DIR)/release-notes-$(RELEASE_TAG).md; \
else \
$(RELEASE_NOTES) --org $(GIT_ORG_NAME) --repo $(GIT_REPO_NAME) --branch $(RELEASE_BRANCH) --start-rev $(PREVIOUS_TAG) --end-rev $(RELEASE_TAG) --output $(RELEASE_NOTES_DIR)/tmp-release-notes.md --list-v2; \
sed 's/\[SIG Cluster Lifecycle\]//g' $(RELEASE_NOTES_DIR)/tmp-release-notes.md > $(RELEASE_NOTES_DIR)/release-notes-$(RELEASE_TAG).md; \
Expand All @@ -584,7 +589,7 @@ release-notes: $(RELEASE_NOTES_DIR) $(RELEASE_NOTES)

.PHONY: promote-images
promote-images: $(KPROMO)
$(KPROMO) pr --project cluster-api-helm --tag $(RELEASE_TAG) --reviewers "$(IMAGE_REVIEWERS)" --fork $(USER_FORK) --image cluster-api-helm-controller
$(KPROMO) pr --project cluster-api-helm --tag $(RELEASE_TAG) --reviewers "$(IMAGE_REVIEWERS)" --fork $(USER_FORK) --image cluster-api-velero-controller

## --------------------------------------
## Docker
Expand Down Expand Up @@ -735,7 +740,7 @@ $(CONVERSION_GEN): # Build conversion-gen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONVERSION_GEN_PKG) $(CONVERSION_GEN_BIN) $(CONVERSION_GEN_VER)

$(CONVERSION_VERIFIER): $(TOOLS_DIR)/go.mod # Build conversion-verifier from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/$(CONVERSION_VERIFIER_BIN) sigs.k8s.io/cluster-api-addon-provider-helm/hack/tools/conversion-verifier
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/$(CONVERSION_VERIFIER_BIN) sigs.k8s.io/cluster-api-addon-provider-velero/hack/tools/conversion-verifier

.PHONY: $(OPENAPI_GEN)
$(OPENAPI_GEN): # Build openapi-gen from tools folder.
Expand All @@ -744,7 +749,7 @@ $(OPENAPI_GEN): # Build openapi-gen from tools folder.
## We are forcing a rebuilt of runtime-openapi-gen via PHONY so that we're always using an up-to-date version.
.PHONY: $(RUNTIME_OPENAPI_GEN)
$(RUNTIME_OPENAPI_GEN): $(TOOLS_DIR)/go.mod # Build openapi-gen from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/$(RUNTIME_OPENAPI_GEN_BIN) sigs.k8s.io/cluster-api-addon-provider-helm/hack/tools/runtime-openapi-gen
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/$(RUNTIME_OPENAPI_GEN_BIN) sigs.k8s.io/cluster-api-addon-provider-velero/hack/tools/runtime-openapi-gen

$(GOTESTSUM): # Build gotestsum from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOTESTSUM_PKG) $(GOTESTSUM_BIN) $(GOTESTSUM_VER)
Expand All @@ -765,7 +770,7 @@ $(SETUP_ENVTEST): # Build setup-envtest from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)

$(TILT_PREPARE): $(TOOLS_DIR)/go.mod # Build tilt-prepare from tools folder.
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/tilt-prepare sigs.k8s.io/cluster-api-addon-provider-helm/hack/tools/tilt-prepare
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/tilt-prepare sigs.k8s.io/cluster-api-addon-provider-velero/hack/tools/tilt-prepare

$(KPROMO):
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KPROMO_PKG) $(KPROMO_BIN) ${KPROMO_VER}
Expand Down
49 changes: 35 additions & 14 deletions api/v1alpha1/veleroinstallation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,46 @@ type VeleroInstallationSpec struct {
helmv1.HelmChartProxySpec `json:",inline"`

State VeleroHelmState `json:"state,omitempty"`

Bucket string `json:"bucket"`

Provider Provider `json:"provider,omitempty"`
}

type Provider struct {
AWS *AWS `json:"aws,omitempty"`
}

type AWS struct {
CredentialMap CredentialMap `json:"credentialMap,omitempty"`

// +optional
Config AWSConfig `json:"config,omitempty"`
}

type AWSConfig struct {
// +optional
Region string `json:"region,omitempty"`

// +optional
S3Url string `json:"s3Url,omitempty"`
}

type VeleroHelmState struct {
DeployNodeAgent bool `json:"deployNodeAgent"`
CleanUpCRDs bool `json:"cleanUpCRDs"`

// Configuration is a bucket configuration
Configuration Configuration `json:"configuration"`
// +optional
Configuration Configuration `json:"configuration,omitempty"`

// Info about the secret to be used by the Velero deployment, which
// should contain credentials for the cloud provider IAM account you've
// set up for Velero.
Credentials Credentials `json:"credentials"`

Plugins []Plugin `json:"plugins,omitempty"`
// +optional
Credentials Credentials `json:"credentials,omitempty"`

//+optional
InitContainers []corev1.Container `json:"initContainers,omitempty"`
}

Expand Down Expand Up @@ -87,20 +111,23 @@ type BackupStorageLocation struct {

// Config containe additional provider-specific configuration. See link above
// for details of required/optional fields for your provider.
Config Config `json:"config,omitempty"`
Config map[string]string `json:"config,omitempty"`
}

type CredentialKey struct {
// Name of the secret used by this backupStorageLocation.
Name string `json:"name,omitempty"`

// Key that contains the secret data to be used.
// +optional
Key string `json:"key,omitempty"`
}

type Config struct {
Region string `json:"region,omitempty"`
S3Url string `json:"s3Url,omitempty"`
type CredentialMap struct {
From string `json:"from,omitempty"`

// +optional
To string `json:"to,omitempty"`
}

type AccessMode string
Expand All @@ -110,12 +137,6 @@ const (
ReadOnly AccessMode = "ReadOnly"
)

type Plugin string

const (
AWS Plugin = "aws"
)

type Credentials struct {
// Set to false if not using a secret for credentials (i.e., use KIAM or WID)
UseSecret bool `json:"useSecret,omitempty"`
Expand Down
Loading
Loading