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

add kubevip #1

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
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# generated by giantswarm/github actions - changes will be overwritten
* @giantswarm/team-honeybadger
* @giantswarm/team-rocket
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# DO NOT EDIT. Generated with:
#
# devctl
#
# https://github.com/giantswarm/devctl/blob/6a704f7e2a8b0f09e82b5bab88f17971af849711/pkg/gen/input/makefile/internal/file/Makefile.template
#

include Makefile.*.mk

##@ 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 commands 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

.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%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
53 changes: 53 additions & 0 deletions Makefile.custom.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
##@ App

OS ?= $(shell go env GOOS 2>/dev/null || echo linux)
ARCH ?= $(shell go env GOARCH 2>/dev/null || echo amd64)
KUSTOMIZE := ./bin/kustomize
KUSTOMIZE_VERSION ?= v4.5.7
YQ = ./bin/yq
YQ_VERSION := 4.31.2

.PHONY: all
all: update-kubevip-chart update-kubevip-cloud-provider-chart increase-chart-version
@$(call say,Sync has been done ✓)

.PHONY: update-kubevip-chart
update-kubevip-chart:
@$(call say,Kubevip helm chart)
./hack/update-kubevip-chart.sh
./hack/common-labels-injector.sh kube-vip

.PHONY: update-kubevip-cloud-provider-chart
update-kubevip-cloud-provider-chart:
@$(call say,Kubevip cloud provider helm chart)
./hack/update-kubevip-cloud-provider-chart.sh
./hack/common-labels-injector.sh kube-vip-cloud-provider

.PHONY: increase-chart-version
increase-chart-version:
@$(call say,Increase parent chart SemVer version)
./hack/increase-chart-version.sh

$(KUSTOMIZE): ## Download kustomize locally if necessary.
@$(call say,Download Kustomize)
mkdir -p $(dir $@)
curl -sfL "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F$(KUSTOMIZE_VERSION)/kustomize_$(KUSTOMIZE_VERSION)_$(OS)_$(ARCH).tar.gz" | tar zxv -C $(dir $@)
chmod +x $@
@echo "kustomize downloaded"

$(YQ): ## Download yq locally if necessary.
@$(call say,Download yq)
curl -sfL https://github.com/mikefarah/yq/releases/download/v$(YQ_VERSION)/yq_$(OS)_$(ARCH) > $@
chmod +x $@
@echo "yq downloaded"


ifndef NO_COLOR
YELLOW=\033[0;33m
# no color
NC=\033[0m
endif

define say
echo "\n$(shell echo "$1 " | tr '[:rune:]' '=')\n $(YELLOW)$1$(NC)\n$(shell echo "$1 " | tr '[:rune:]' '=')"
endef
48 changes: 48 additions & 0 deletions Makefile.gen.app.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# DO NOT EDIT. Generated with:
#
# devctl
#
# https://github.com/giantswarm/devctl/blob/eea19f200d7cfd27ded22474b787563bbfdb8ec4/pkg/gen/input/makefile/internal/file/Makefile.gen.app.mk.template
#

##@ App

YQ=docker run --rm -u $$(id -u) -v $${PWD}:/workdir mikefarah/yq:4.29.2
HELM_DOCS=docker run --rm -u $$(id -u) -v $${PWD}:/helm-docs jnorwood/helm-docs:v1.11.0

ifdef APPLICATION
DEPS := $(shell find $(APPLICATION)/charts -maxdepth 2 -name "Chart.yaml" -printf "%h\n")
endif

.PHONY: lint-chart check-env update-chart helm-docs update-deps $(DEPS)

lint-chart: IMAGE := giantswarm/helm-chart-testing:v3.0.0-rc.1
lint-chart: check-env ## Runs ct against the default chart.
@echo "====> $@"
rm -rf /tmp/$(APPLICATION)-test
mkdir -p /tmp/$(APPLICATION)-test/helm
cp -a ./helm/$(APPLICATION) /tmp/$(APPLICATION)-test/helm/
architect helm template --dir /tmp/$(APPLICATION)-test/helm/$(APPLICATION)
docker run -it --rm -v /tmp/$(APPLICATION)-test:/wd --workdir=/wd --name ct $(IMAGE) ct lint --validate-maintainers=false --charts="helm/$(APPLICATION)"
rm -rf /tmp/$(APPLICATION)-test

update-chart: check-env ## Sync chart with upstream repo.
@echo "====> $@"
vendir sync
$(MAKE) update-deps

update-deps: check-env $(DEPS) ## Update Helm dependencies.
cd $(APPLICATION) && helm dependency update

$(DEPS): check-env ## Update main Chart.yaml with new local dep versions.
dep_name=$(shell basename $@) && \
new_version=`$(YQ) .version $(APPLICATION)/charts/$$dep_name/Chart.yaml` && \
$(YQ) -i e "with(.dependencies[]; select(.name == \"$$dep_name\") | .version = \"$$new_version\")" $(APPLICATION)/Chart.yaml

helm-docs: check-env ## Update $(APPLICATION) README.
$(HELM_DOCS) -c $(APPLICATION) -g $(APPLICATION)

check-env:
ifndef APPLICATION
$(error APPLICATION is not defined)
endif
32 changes: 32 additions & 0 deletions config/kube-vip-cloud-provider/overwrites/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v2
name: kube-vip-cloud-provider
description: A Helm chart for kube-vip cloud provider

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

#* This is the upstream chart version which is released as a specific tag in the same repo as `kube-vip`.
#* Renovate below watches releases that match `kube-vip-cloud-provider-x.y.z`.
# renovate-kube-vip-cloud-provider: kube-vip/helm-charts
version: 0.2.2

#* This is the app's version of the application being deployed.
#* It overwrites the value of the upstream chart above which isn't well maintained.
#* Renovate watches for standard versioning as the releases are normal in this repo.
# repo: kube-vip/kube-vip-cloud-provider
appVersion: v0.0.5

icon: https://github.com/kube-vip/kube-vip/raw/main/kube-vip.png

maintainers:
- name: kube-vip

annotations:
application.giantswarm.io/team: "rocket"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
data:
{{- if .Values.rangeGlobal }}
range-global: {{ .Values.rangeGlobal }}
{{- end }}
{{- if .Values.cidrGlobal }}
cidr-global: {{ .Values.cidrGlobal }}
{{- end }}
kind: ConfigMap
metadata:
name: kubevip
namespace: {{ .Release.Namespace | default "kube-system" }}
labels:
{{- include "labels.common" $ | nindent 4 }}
46 changes: 46 additions & 0 deletions config/kube-vip-cloud-provider/overwrites/templates/npols.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-kubevip-cp-talk-to-apiserver
namespace: {{ .Release.Namespace | default "kube-system" }}
labels:
{{- include "labels.common" $ | nindent 4 }}
spec:
podSelector:
matchLabels:
{{- include "kube-vip-cloud-provider.selectorLabels" . | nindent 6 }}
policyTypes:
- Egress
egress:
- ports:
- port: 443
protocol: TCP
- port: 6443
protocol: TCP
to:
- podSelector:
matchLabels:
component: kube-apiserver
---
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: allow-kubevip-cp-talk-to-apiserver
namespace: {{ .Release.Namespace | default "kube-system" }}
labels:
{{- include "labels.common" $ | nindent 4 }}
spec:
endpointSelector:
matchLabels:
{{- include "kube-vip-cloud-provider.selectorLabels" . | nindent 6 }}
egress:
- toEntities:
- kube-apiserver
toPorts:
- ports:
- port: "443"
protocol: TCP
- port: "6443"
protocol: TCP
---
32 changes: 32 additions & 0 deletions config/kube-vip/overwrites/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v2
name: kube-vip
description: A Helm chart for kube-vip

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

#* This is the upstream chart version which is released as a specific tag in the same repo as `kube-vip-cloud-provider`.
#* Renovate below watches releases that match `kube-vip-x.y.z`.
# renovate-kube-vip: kube-vip/helm-charts
version: 0.6.2

#* This is the app's version of the application being deployed.
#* It overwrites the value of the upstream chart above which isn't well maintained.
#* Renovate watches for standard versioning as the releases are normal in this repo.
# repo: kube-vip/kube-vip
appVersion: v0.8.4

icon: https://github.com/kube-vip/kube-vip/raw/main/kube-vip.png

maintainers:
- name: kube-vip

annotations:
application.giantswarm.io/team: "rocket"
15 changes: 15 additions & 0 deletions hack/clone-git-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -euo pipefail
set -x

base_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)

REPO="${1}"
BRANCH_OR_TAG="${2}"
CLONE_FOLDER="${3}"

cd "$base_dir/tmp"
rm -Rf "$CLONE_FOLDER"

git clone --depth=1 --branch "${BRANCH_OR_TAG}" "https://github.com/${REPO}.git" "$CLONE_FOLDER"
42 changes: 42 additions & 0 deletions hack/common-labels-injector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -euo pipefail

base_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)

CHART_NAME="${1}"
TEMPLATE_FOLDER="$base_dir/helm/cloud-provider-proxmox/charts/$CHART_NAME/templates"

for file in "$TEMPLATE_FOLDER"/*yaml
do
echo "Droping unnecessary labels"
sed -i "/kube-vip-cloud-provider.labels/d" "$file"
sed -i "/kube-vip.labels/d" "$file"

echo "Injecting common labels to $file"
if grep -q "labels.common" < "$file"; then
echo "Common labels already exist.Skipping"
continue
fi

# inject common labels to resources that have already labels section
injected='{{- include "labels.common" $ | nindent 4 }}'
sed -i -z "s/\n\s\slabels:/\n labels:\n $injected/g" "$file"

# inject common labels to list resources that have already labels section
if grep -q "kind: List" < "$file"; then
injected='{{- include "labels.common" $ | nindent 6 }}'
sed -i -z "s/\n\s\s\s\slabels:/\n labels:\n $injected/g" "$file"
fi

if ! grep -q "^ labels:" < "$file"; then
# labels section doesn't exist. adding it.
injected='{{- include "labels.common" $ | nindent 4 }}'
sed -i -z "s/\nmetadata:\n/\nmetadata:\n labels:\n $injected\n/g" "$file"
fi

if ! grep -q "labels.common" < "$file"; then
echo "Couldn't inject common labels. Please check. Exiting."
exit 1
fi
done
42 changes: 42 additions & 0 deletions hack/increase-chart-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -eo pipefail
set -x

if [[ -z "${GITHUB_ACTIONS}" ]]; then
# Not running in a GH action

chart_file="helm/cloud-provider-proxmox/Chart.yaml"

current_version=$(yq e '.version' $chart_file)

update_version() {
new_version=$1
yq e -i ".version = \"$new_version\" | .appVersion = \"$new_version\"" "$chart_file"
echo "Chart version updated: $current_version -> $new_version"
}

read -p "Do you want to update the chart's version? [n] No, [m] Minor, [p] Patch: " choice

case $choice in
"n")
echo "No version update."
;;
"m")
new_version=$(echo $current_version | awk -F. '{$2++; printf "%d.%d.%d",$1,$2,$3}')
update_version "$new_version"
;;
"p")
new_version=$(echo $current_version | awk -F. '{$3++; printf "%d.%d.%d",$1,$2,$3}')
update_version "$new_version"
;;
*)
echo "Invalid choice. Please enter n, m, or p."
;;
esac

echo "\n*********************************\n🔔 Please update the CHANGELOG 🔔\n*********************************"

else
echo "Running in GH Action - skipping interactive task"
fi
24 changes: 24 additions & 0 deletions hack/replace-image-registries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -euo pipefail
set -x

# This script replaces any image registry/repository to our own.
# It also replaces the default image names with our retagged names.

FILEPATH="${1}"
UPSTREAM_IMAGE="${2}"
GS_IMAGE="${3}"

REGISTRY='gsoci.azurecr.io'
REPOSITORY='giantswarm'

# Replace the registry section to our own.
sed -i "s|\(image:\s*\)[^/]\+/|\1$REGISTRY/|" $FILEPATH

# Replace the repository section to our own, including subpaths.
sed -i "s|\(image:\s*[^/]\+\)/.*/|\1/$REPOSITORY/|" $FILEPATH

# Replace upstream image names with our retagged names.
# e.g. https://github.com/giantswarm/retagger/blob/4fa7dff7f68ff5141267c4e788cea6ded1de6277/images/customized-images.yaml#L97-L99

sed -i "/image:/ s|$REGISTRY/$REPOSITORY/$UPSTREAM_IMAGE|$REGISTRY/$REPOSITORY/$GS_IMAGE|g" $FILEPATH
Loading