Skip to content

Commit

Permalink
Merge branch 'main' into av/health-ready-pod
Browse files Browse the repository at this point in the history
Signed-off-by: Alena Varkockova <varkockova.a@gmail.com>
  • Loading branch information
alenkacz committed Aug 20, 2020
2 parents 9a525c4 + ee46809 commit 19644e6
Show file tree
Hide file tree
Showing 30 changed files with 1,549 additions and 372 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ linters:
- dupl
- goconst
- lll
- stylecheck
run:
build-tags:
- integration
Expand Down
122 changes: 76 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ SUPPORTED_PLATFORMS = amd64 arm64

export GO111MODULE=on

.PHONY: all
all: test manager
.PHONY: help
help: ## Show this help screen
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


##############################
# Tests #
##############################

##@ Tests

# Run unit tests
.PHONY: test
test:
test: ## Runs unit tests
ifdef _INTELLIJ_FORCE_SET_GOFLAGS
# Run tests from a Goland terminal. Goland already set '-mod=readonly'
go test ./pkg/... ./cmd/... -v -coverprofile cover.out
Expand All @@ -38,7 +50,7 @@ e2e-test: cli-fast manager-fast

.PHONY: integration-test
# Run integration tests
integration-test: cli-fast manager-fast
integration-test: cli-fast manager-fast ##Runs integration tests
TEST_ONLY=$(TEST) ./hack/run-integration-tests.sh

.PHONY: operator-test
Expand All @@ -51,11 +63,20 @@ upgrade-test: cli-fast manager-fast

.PHONY: test-clean
# Clean test reports
test-clean:
test-clean: ## cleans test outputs
rm -f cover.out cover-integration.out

##############################
# Development #
##############################

##@ Development

.PHONY: all
all: test manager ## Build manager and runs unit tests

.PHONY: lint
lint:
lint: ## Run golangci-lint
ifneq (${GOLANGCI_LINT_VER}, "$(shell golangci-lint --version 2>/dev/null | cut -b 27-32)")
./hack/install-golangcilint.sh
endif
Expand All @@ -70,11 +91,11 @@ prebuild: generate lint


# Build manager binary
manager: prebuild manager-fast
manager: prebuild manager-fast ## Builds manager

.PHONY: manager-fast
# Build manager binary
manager-fast:
manager-fast: ## Builds manager without code generation
# developer convenience for platform they are running
go build -ldflags "${LDFLAGS}" -o bin/$(EXECUTABLE) github.com/kudobuilder/kudo/cmd/manager

Expand All @@ -86,7 +107,7 @@ manager-clean:

.PHONY: run
# Run against the configured Kubernetes cluster in ~/.kube/config
run:
run: ## Runs Manager locally (requires ngrok or webhook management)
# for local development, webhooks are disabled by default
# if you enable them, you have to take care of providing the TLS certs locally
go run -ldflags "${LDFLAGS}" ./cmd/manager
Expand All @@ -96,9 +117,52 @@ run:
deploy:
go run -ldflags "${LDFLAGS}" ./cmd/kubectl-kudo init

.PHONY: cli
# Build CLI
cli: prebuild cli-fast ## Builds CLI with code generation

.PHONY: cli-clean
# Clean CLI build
cli-clean:
rm -f bin/${CLI}

# Install CLI
cli-install: ## Installs kubectl-kudo to GOBIN
go install -ldflags "${LDFLAGS}" ./cmd/kubectl-kudo

.PHONY: clean
# Clean all
clean: cli-clean test-clean manager-clean ## Cleans cli, tests and manager

# Build CLI but don't lint or run code generation first.
cli-fast:
go build -ldflags "${LDFLAGS}" -o bin/${CLI} ./cmd/kubectl-kudo

.PHONY: docker-build
# Build the docker image for each supported platform
docker-build: generate lint ## Docker Build (for dev only)
docker build --build-arg ldflags_arg="$(LDFLAGS)" -f Dockerfile -t $(DOCKER_IMG):$(DOCKER_TAG) .


# requires manifests. generate-manifests should be run first
# quickly sets a local dev env with the minimum necessary configurations to run
# the kudo manager locally. after running dev-ready, it is possible to 'make run' or run from an editor for debugging.
# it currently does require ngrok.
.PHONY: dev-ready
dev-ready: ## Installs KUDO manifests and updates webhook to work with ngrok
./hack/deploy-dev-prereqs.sh
./hack/update-webhook-config.sh


##############################
# Generate Artifacts #
##############################

##@ Generate

.PHONY: generate
# Generate code
generate:
generate: ## (Re)Generates CRDs and go-bindata
ifneq ($(shell go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools), $(shell controller-gen --version 2>/dev/null | cut -b 10-))
@echo "(Re-)installing controller-gen. Current version: $(controller-gen --version 2>/dev/null | cut -b 10-). Need $(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools)"
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$$(go list -f '{{.Version}}' -m sigs.k8s.io/controller-tools)
Expand All @@ -114,31 +178,6 @@ endif
generate-clean:
rm -rf ./hack/code-gen

# Build CLI but don't lint or run code generation first.
cli-fast:
go build -ldflags "${LDFLAGS}" -o bin/${CLI} ./cmd/kubectl-kudo

.PHONY: cli
# Build CLI
cli: prebuild cli-fast

.PHONY: cli-clean
# Clean CLI build
cli-clean:
rm -f bin/${CLI}

# Install CLI
cli-install:
go install -ldflags "${LDFLAGS}" ./cmd/kubectl-kudo

.PHONY: clean
# Clean all
clean: cli-clean test-clean manager-clean

.PHONY: docker-build
# Build the docker image for each supported platform
docker-build: generate lint
docker build --build-arg ldflags_arg="$(LDFLAGS)" -f Dockerfile -t $(DOCKER_IMG):$(DOCKER_TAG) .

.PHONY: imports
# used to update imports on project. NOT a linter.
Expand All @@ -152,7 +191,7 @@ endif
# used to update the golden files present in ./pkg/.../testdata
# example: make update-golden
# tests in update==true mode show as failures
update-golden:
update-golden: ## Updates golden files
go test ./pkg/... -v -mod=readonly --update=true

.PHONY: todo
Expand All @@ -171,7 +210,7 @@ todo:
# updating webhook requires ngrok to be running and updates the wh-config with the latest
# ngrok configuration. ngrok config changes for each restart which is why this is a separate target
.PHONY: update-webhook-config
update-webhook-config:
update-webhook-config: # Updates webhook when using ngrok
./hack/update-webhook-config.sh

# generates manifests from the kudo cli (kudo init) and captures the manifests needed for
Expand All @@ -180,12 +219,3 @@ update-webhook-config:
.PHONY: generate-manifests
generate-manifests:
./hack/update-manifests.sh

# requires manifests. generate-manifests should be run first
# quickly sets a local dev env with the minimum necessary configurations to run
# the kudo manager locally. after running dev-ready, it is possible to 'make run' or run from an editor for debugging.
# it currently does require ngrok.
.PHONY: dev-ready
dev-ready:
./hack/deploy-dev-prereqs.sh
./hack/update-webhook-config.sh
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ Please refer to the [getting started guide](https://kudo.dev/docs/) documentatio

## Community Meetings

We have open community meetings every 2nd and 4th Wednesday of the month at 9:00 a.m. PST. (17:00 UTC)
We have open community meetings every 2 weeks on Thursday at 9:00 a.m. PT. (17:00 UTC)

* Agenda and Notes: https://docs.google.com/document/d/1UqgtCMUHSsOohZYF8K7zX8WcErttuMSx7NbvksIbZgg
* Zoom Meeting: https://d2iq.zoom.us/j/443128842
* [Agenda and Notes](https://docs.google.com/document/d/1UqgtCMUHSsOohZYF8K7zX8WcErttuMSx7NbvksIbZgg)
* [Zoom Meeting](https://d2iq.zoom.us/j/443128842)


## Community, Events, Discussion, Contribution, and Support
Expand All @@ -32,4 +32,4 @@ Learn more on how to engage with the KUDO community on the [community page](http

* Read the [code of conduct](code-of-conduct.md)
* Read the [contribution guide](CONTRIBUTING.md)
* Details on running and debugging locally read [development guide](development.md)
* Details on running and debugging locally read [development guide](development.md)
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ go 1.14

require (
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.1.0
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/go-bindata/go-bindata/v3 v3.1.3
github.com/google/go-cmp v0.5.1
github.com/gosuri/uitable v0.0.4
github.com/huandu/xstrings v1.3.1 // indirect
github.com/kisielk/errcheck v1.4.0 // indirect
github.com/kudobuilder/kuttl v0.5.1
github.com/kudobuilder/kuttl v0.6.0
github.com/manifoldco/promptui v0.7.0
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/onsi/ginkgo v1.14.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QL
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:90Ly+6UfUypEF6vvvW5rQIv9opIL8CbmW9FT20LDQoY=
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8=
Expand Down Expand Up @@ -302,6 +303,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kudobuilder/kuttl v0.5.1 h1:wLVfztMqVCGBws6RweEfDPVXaa+ZRBirAJjJ/HiklMA=
github.com/kudobuilder/kuttl v0.5.1/go.mod h1:o9M5BBmunm69oMnPjvNGb6biz3nm5AswAdJ0EIhTJQA=
github.com/kudobuilder/kuttl v0.6.0 h1:5mc65Q4yShSStcCKxl672kWhTPm0kQq0nl6z6GRcxm8=
github.com/kudobuilder/kuttl v0.6.0/go.mod h1:HAaSKGN3P7VJqbBIWQlbhrkvFcNe013oLkwvk0lM1kE=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
Expand Down
41 changes: 20 additions & 21 deletions pkg/controller/instance/instance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1"
kudov1beta1 "github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1"
"github.com/kudobuilder/kudo/pkg/engine"
"github.com/kudobuilder/kudo/pkg/engine/renderer"
Expand Down Expand Up @@ -201,7 +200,7 @@ func (r *Reconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) {
return reconcile.Result{}, err
}

if planStatus.Status == v1beta1.ExecutionPending {
if planStatus.Status == kudov1beta1.ExecutionPending {
log.Printf("InstanceController: Going to start execution of plan '%s' on instance %s/%s", plan, instance.Namespace, instance.Name)
r.Recorder.Event(instance, "Normal", "PlanStarted", fmt.Sprintf("Execution of plan %s started", plan))
}
Expand Down Expand Up @@ -420,8 +419,8 @@ func ParamsMap(instance *kudov1beta1.Instance, operatorVersion *kudov1beta1.Oper
}

// PipesMap generates {{ Pipes.* }} map of keys and values which is later used during template rendering.
func PipesMap(planName string, plan *v1beta1.Plan, tasks []v1beta1.Task, emeta *engine.Metadata) (map[string]string, error) {
taskByName := func(name string) (*v1beta1.Task, bool) {
func PipesMap(planName string, plan *kudov1beta1.Plan, tasks []kudov1beta1.Task, emeta *engine.Metadata) (map[string]string, error) {
taskByName := func(name string) (*kudov1beta1.Task, bool) {
for _, t := range tasks {
if t.Name == name {
return &t, true
Expand Down Expand Up @@ -462,7 +461,7 @@ func PipesMap(planName string, plan *v1beta1.Plan, tasks []v1beta1.Task, emeta *
// scheduled plan (UID has changed) and returns updated plan status. In this case Plan/phase/step statuses are set
// to ExecutionPending meaning that the controller will restart plan execution. Otherwise (the plan is old),
// nothing is changed and the existing plan status is returned.
func resetPlanStatusIfPlanIsNew(i *v1beta1.Instance, plan string, uid types.UID) (*v1beta1.PlanStatus, error) {
func resetPlanStatusIfPlanIsNew(i *kudov1beta1.Instance, plan string, uid types.UID) (*kudov1beta1.PlanStatus, error) {
ps := i.PlanStatus(plan)
if ps == nil {
return nil, fmt.Errorf("failed to find planStatus for plan '%s'", plan)
Expand All @@ -481,28 +480,28 @@ func resetPlanStatusIfPlanIsNew(i *v1beta1.Instance, plan string, uid types.UID)
// ensurePlanStatusInitialized initializes plan status for all plans this instance supports it does not trigger run
// of any plan it either initializes everything for a fresh instance without any status or tries to adjust status
// after OV was updated
func ensurePlanStatusInitialized(i *v1beta1.Instance, ov *v1beta1.OperatorVersion) {
func ensurePlanStatusInitialized(i *kudov1beta1.Instance, ov *kudov1beta1.OperatorVersion) {
if i.Status.PlanStatus == nil {
i.Status.PlanStatus = make(map[string]v1beta1.PlanStatus)
i.Status.PlanStatus = make(map[string]kudov1beta1.PlanStatus)
}

for planName, plan := range ov.Spec.Plans {
if _, ok := i.Status.PlanStatus[planName]; !ok {
planStatus := v1beta1.PlanStatus{
planStatus := kudov1beta1.PlanStatus{
Name: planName,
Status: v1beta1.ExecutionNeverRun,
Phases: make([]v1beta1.PhaseStatus, 0),
Status: kudov1beta1.ExecutionNeverRun,
Phases: make([]kudov1beta1.PhaseStatus, 0),
}
for _, phase := range plan.Phases {
phaseStatus := v1beta1.PhaseStatus{
phaseStatus := kudov1beta1.PhaseStatus{
Name: phase.Name,
Status: v1beta1.ExecutionNeverRun,
Steps: make([]v1beta1.StepStatus, 0),
Status: kudov1beta1.ExecutionNeverRun,
Steps: make([]kudov1beta1.StepStatus, 0),
}
for _, step := range phase.Steps {
stepStatus := v1beta1.StepStatus{
stepStatus := kudov1beta1.StepStatus{
Name: step.Name,
Status: v1beta1.ExecutionNeverRun,
Status: kudov1beta1.ExecutionNeverRun,
}
phaseStatus.Steps = append(phaseStatus.Steps, stepStatus)
}
Expand All @@ -515,7 +514,7 @@ func ensurePlanStatusInitialized(i *v1beta1.Instance, ov *v1beta1.OperatorVersio

// scheduledPlan method returns currently scheduled plan and its UID from Instance.Spec.PlanExecution field. However, due
// to an edge case with instance deletion, this method also schedules the 'cleanup' plan if necessary (see the comments below)
func scheduledPlan(i *v1beta1.Instance, ov *v1beta1.OperatorVersion) (string, types.UID) {
func scheduledPlan(i *kudov1beta1.Instance, ov *kudov1beta1.OperatorVersion) (string, types.UID) {
// Instance deletion is an edge case where the admission webhook *can not* populate the Spec.PlanExecution.PlanName
// with the 'cleanup' plan. So we have to do it here ourselves. Only if:
// 1. Instance is being deleted
Expand All @@ -524,17 +523,17 @@ func scheduledPlan(i *v1beta1.Instance, ov *v1beta1.OperatorVersion) (string, ty
// we set the Spec.PlanExecution.PlanName = 'cleanup'
hasToScheduleCleanupAfterDeletion := func() bool {
shouldCleanup := i.IsDeleting() && kudov1beta1.CleanupPlanExists(ov)
cleanupNeverRun := i.PlanStatus(v1beta1.CleanupPlanName) == nil || i.PlanStatus(v1beta1.CleanupPlanName).Status == kudov1beta1.ExecutionNeverRun
cleanupNotScheduled := i.Spec.PlanExecution.PlanName != v1beta1.CleanupPlanName
cleanupNeverRun := i.PlanStatus(kudov1beta1.CleanupPlanName) == nil || i.PlanStatus(kudov1beta1.CleanupPlanName).Status == kudov1beta1.ExecutionNeverRun
cleanupNotScheduled := i.Spec.PlanExecution.PlanName != kudov1beta1.CleanupPlanName

return shouldCleanup && cleanupNeverRun && cleanupNotScheduled
}
if hasToScheduleCleanupAfterDeletion() {
log.Printf("InstanceController: Instance %s/%s is being deleted. Scheduling '%s' plan.", i.Namespace, i.Name, v1beta1.CleanupPlanName)
log.Printf("InstanceController: Instance %s/%s is being deleted. Scheduling '%s' plan.", i.Namespace, i.Name, kudov1beta1.CleanupPlanName)

i.Spec.PlanExecution.PlanName = v1beta1.CleanupPlanName
i.Spec.PlanExecution.PlanName = kudov1beta1.CleanupPlanName
i.Spec.PlanExecution.UID = uuid.NewUUID()
i.Spec.PlanExecution.Status = v1beta1.ExecutionNeverRun
i.Spec.PlanExecution.Status = kudov1beta1.ExecutionNeverRun
}

return i.Spec.PlanExecution.PlanName, i.Spec.PlanExecution.UID
Expand Down
Loading

0 comments on commit 19644e6

Please sign in to comment.