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

[minor] Update k8s resources to support k8s v1.22 #156

Open
wants to merge 20 commits into
base: master
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 .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# BUILD
- uses: actions/setup-go@v1
with:
go-version: '1.17.2'
go-version: '1.18.10'

- uses: actions/checkout@v1
with:
Expand Down
40 changes: 21 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GITHUB_API_URL ?= https://api.github.com
GITHUB_TOKEN ?=
GITHUB_REPO ?= agoda-com/samsahai
GO_VERSION ?= 1.17.2
GOLANGCI_LINT_VERSION ?= 1.41.1
GOLANGCI_LINT_VERSION ?= 1.55.2

GO ?= go

Expand All @@ -17,25 +17,25 @@ GOBIN=$(shell $(GO) env GOPATH)/bin
else
GOBIN=$(shell $(GO) env GOBIN)
endif
KUBEBUILDER_VERSION ?= 2.2.0
KUBEBULIDER_FILENAME = kubebuilder_$(KUBEBUILDER_VERSION)_$(OS)_$(ARCH)
KUBEBUILDER_VERSION ?= 3.13.0
KUBEBULIDER_FILENAME = kubebuilder_$(OS)_$(ARCH)
KUBEBUILDER_PATH ?= /usr/local/kubebuilder/
GORELEASER_VERSION ?= 0.124.1
K3S_DOCKER_IMAGE ?= rancher/k3s:v1.20.11-k3s2
K3S_DOCKER_IMAGE ?= rancher/k3s:v1.22.17-k3s1
KUBECONFIG = /tmp/s2h/k3s-kubeconfig
K3S_DOCKER_NAME ?= s2h-k3s-server
K3S_PORT ?= 6443
K8S_VERSION ?= 1.21.0
K8S_VERSION ?= 1.22.0
KUSTOMIZE_VERSION ?= 3.8.6
HELM_VERSION ?= 3.6.3
HELM_VERSION ?= 3.13.3
POD_NAMESPACE ?= default

GO111MODULE := on
SUDO ?=
INSTALL_DIR ?= $(PWD)/bin/
OS = $$(echo `uname`|tr '[:upper:]' '[:lower:]')
OS2 = $$(if [ "$$(uname|tr '[:upper:]' '[:lower:]')" = "linux" ]; then echo linux; elif [ "$$(uname|tr '[:upper:]' '[:lower:]')" = "darwin" ]; then echo osx; fi)
ARCH = $$(if [ "$$(uname -m)" = "x86" ]; then echo 386; elif [ "$$(uname -m)" = "x86_64" ]; then echo amd64; fi)
ARCH = $$(if [ "$$(uname -m)" = "x86" ]; then echo 386; elif [ "$$(uname -m)" = "x86_64" ]; then echo amd64; elif [ "$$(uname -m)" = "arm64" ]; then echo arm64; fi)
ARCHx86 = $$(if [ "$$(uname -m)" = "x86" ]; then echo x86_32; elif [ "$$(uname -m)" = "x86_64" ]; then echo x86_64; fi)
DEBUG ?=
ARCHIVE_EXT ?= .tar.gz
Expand Down Expand Up @@ -160,8 +160,8 @@ prepare-env-e2e:
$(KUBECTL) -n kube-system wait pods -l k8s-app=kube-dns --for=condition=Ready --timeout=5m; \
until $(KUBECTL) -n kube-system get pods -l app=svclb-traefik 2>&1 | grep -iv "no resources found" >/dev/null; do sleep 1; done; \
$(KUBECTL) -n kube-system wait pods -l app=svclb-traefik --for=condition=Ready --timeout=5m; \
until $(KUBECTL) -n kube-system get pods -l app=traefik 2>&1 | grep -iv "no resources found" >/dev/null; do sleep 1; done; \
$(KUBECTL) -n kube-system wait pods -l app=traefik --for=condition=Ready --timeout=5m; \
until $(KUBECTL) -n kube-system get pods -l app.kubernetes.io/name=traefik 2>&1 | grep -iv "no resources found" >/dev/null; do sleep 1; done; \
$(KUBECTL) -n kube-system wait pods -l app.kubernetes.io/name=traefik --for=condition=Ready --timeout=5m; \
$(KUBECTL) create ns samsahai-system || echo 'namespace "samsahai-system" already exist'; \
\
\
Expand Down Expand Up @@ -367,12 +367,15 @@ install-go:

.install-kubebuilder: export APP_NAME = kubebuilder
.install-kubebuilder: export APP_VERSION = $(KUBEBUILDER_VERSION)
.install-kubebuilder: export _DOWNLOAD_URL = https://go.kubebuilder.io/dl/latest/$(OS)/$(ARCH)
.install-kubebuilder:
export _FILENAME="$(KUBEBULIDER_FILENAME)"; \
export _DOWNLOAD_URL="https://github.com/kubernetes-sigs/kubebuilder/releases/download/v$(KUBEBUILDER_VERSION)/$$_FILENAME.tar.gz"; \
export _MOVE_CMD="$(MKDIR) -p /usr/local/$(APP_NAME)/bin && $(MV) $(TMP_DIR)/$$_FILENAME/bin/* /usr/local/$(APP_NAME)/bin/"; \
export INSTALL_DIR="/usr/local/$(APP_NAME)/bin/"; \
$(MAKE) .install-archive
$(MKDIR) -p $(TMP_DIR); \
$(PWD); \
$(CURL) -sLo $(TMP_DIR)/$(APP_NAME) $(_DOWNLOAD_URL); \
$(CHMOD) +x $(TMP_DIR)/$(APP_NAME); \
$(MKDIR) -p /usr/local/$(APP_NAME)/bin; \
$(MV) $(TMP_DIR)/$(APP_NAME) /usr/local/$(APP_NAME)/bin/; \
echo $(APP_NAME) $(APP_VERSION) installed;

.install-helm: export APP_NAME = helm
.install-helm: export APP_VERSION = $(HELM_VERSION)
Expand Down Expand Up @@ -473,21 +476,20 @@ endif

.install-gotools:
@echo installing gotools
@GO111MODULE=off $(GO) get -u \
$(GO) get -d \
golang.org/x/tools/cmd/goimports \
github.com/golang/protobuf/protoc-gen-go \
github.com/twitchtv/twirp/protoc-gen-twirp

# Produce CRDs that work back to Kubernetes 1.21 (no version conversion)
CRD_OPTIONS ?= "crd"

CONTROLLER_GEN=$(GO) run $$GOPATH/pkg/mod/github.com/phantomnat/controller-tools@v0.2.4-1/cmd/controller-gen/main.go
CONTROLLER_GEN=$(GO) run $$GOPATH/pkg/mod/sigs.k8s.io/controller-tools@v0.13.0/cmd/controller-gen/main.go

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(GO) get sigs.k8s.io/controller-tools
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." crd:crdVersions=v1 output:crd:artifacts:config=config/crds output:none
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." crd:crdVersions=v1beta1 output:crd:artifacts:config=test/data/crds output:none
$(CONTROLLER_GEN) paths="./..." crd:crdVersions=v1 output:crd:artifacts:config=config/crds output:none
$(CONTROLLER_GEN) paths="./..." crd:crdVersions=v1 output:crd:artifacts:config=test/data/crds output:none

# Generate code
generate: controller-gen
Expand Down
2 changes: 1 addition & 1 deletion api/v1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ func (cs *ConfigStatus) SetCondition(cond ConfigConditionType, status corev1.Con
}

// +k8s:deepcopy-gen=false
//ComponentValues represents values of a component chart
// ComponentValues represents values of a component chart
type ComponentValues map[string]interface{}

func (in *ComponentValues) DeepCopyInto(out *ComponentValues) {
Expand Down
19 changes: 12 additions & 7 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions cmd/samsahai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
cr "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/config"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

s2hv1 "github.com/agoda-com/samsahai/api/v1"
docs2 "github.com/agoda-com/samsahai/docs"
Expand Down Expand Up @@ -119,9 +119,11 @@ func startCtrlCmd() *cobra.Command {

// Create a new Cmd to provide shared dependencies and start components
logger.Info("setting up manager")
mgr, err := cr.NewManager(cfg, manager.Options{
Scheme: scheme,
MetricsBindAddress: ":" + httpMetricPort,
mgr, err := manager.New(cfg, manager.Options{
Scheme: scheme,
Metrics: server.Options{
BindAddress: ":" + httpMetricPort,
},
})
if err != nil {
logger.Error(err, "unable to set up overall controller manager")
Expand Down
9 changes: 6 additions & 3 deletions cmd/staging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

s2hv1 "github.com/agoda-com/samsahai/api/v1"
s2h "github.com/agoda-com/samsahai/internal"
Expand Down Expand Up @@ -117,9 +118,11 @@ func startCtrlCmd() *cobra.Command {
// Create a new Cmd to provide shared dependencies and start components
logger.Info("setting up manager")
mgr, err := manager.New(cfg, manager.Options{
Scheme: scheme,
MetricsBindAddress: ":" + httpMetricPort,
Namespace: namespace,
Scheme: scheme,
Metrics: server.Options{
BindAddress: ":" + httpMetricPort,
},
LeaderElectionNamespace: namespace,
})
if err != nil {
logger.Error(err, "unable to set up overall controller manager")
Expand Down
10 changes: 0 additions & 10 deletions config/chart/samsahai/templates/clusterrole-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@ rules:
- get
- list
- watch
{{- if .Values.rbac.pspEnabled }}
- apiGroups:
- policy
resources:
- podsecuritypolicies
verbs:
- use
resourceNames:
- {{ include "samsahai.fullname" . }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
2 changes: 1 addition & 1 deletion config/chart/samsahai/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "samsahai.fullname" . -}}
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}
Expand Down
38 changes: 0 additions & 38 deletions config/chart/samsahai/templates/podsecuritypolicy.yaml

This file was deleted.

7 changes: 1 addition & 6 deletions config/chart/samsahai/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,4 @@ nodeSelector: {}

tolerations: []

affinity: {}

## Enable RBAC as per https://github.com/kubernetes/ingress/tree/master/examples/rbac/nginx and https://github.com/kubernetes/ingress/issues/266
rbac:
pspEnabled: false
pspUseAppArmor: false
affinity: {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: activepromotionhistories.env.samsahai.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crds/env.samsahai.io_activepromotions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: activepromotions.env.samsahai.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crds/env.samsahai.io_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: configs.env.samsahai.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crds/env.samsahai.io_desiredcomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: desiredcomponents.env.samsahai.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: pullrequestqueuehistories.env.samsahai.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crds/env.samsahai.io_pullrequestqueues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: pullrequestqueues.env.samsahai.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crds/env.samsahai.io_pullrequesttriggers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: pullrequesttriggers.env.samsahai.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crds/env.samsahai.io_queuehistories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: queuehistories.env.samsahai.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/crds/env.samsahai.io_queues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: (devel)
controller-gen.kubebuilder.io/version: ""
creationTimestamp: null
name: queues.env.samsahai.io
spec:
Expand Down
Loading
Loading