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

State management #1

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
fdd0213
Don't generate HMC chart with helmify
eromanova Aug 1, 2024
5189d75
Remove kubebuilder RBAC markers and unused RBAC roles
eromanova Aug 1, 2024
fd9c2f5
Several HMC chart improvements
eromanova Aug 1, 2024
7c84866
Add admission webhook to HMC controller
eromanova Aug 1, 2024
80bf244
Enable admission webhook once the cert manager API is ready
eromanova Aug 2, 2024
3f8bd34
Apply default deployment conifguration by the admission controller
eromanova Aug 6, 2024
9452379
Merge pull request #125 from eromanova/hmc-chart-improvements
Kshatrix Aug 8, 2024
dd85a94
Forbid Management removal if Deployments exist
Kshatrix Aug 8, 2024
6cb1380
Merge pull request #160 from Mirantis/mgmt-delete
Kshatrix Aug 8, 2024
13a0fe7
Do not overwrite HMC values passed with the initial installation
eromanova Aug 8, 2024
03d8e20
Add a note about HMC customization limitations
eromanova Aug 8, 2024
56b844c
Apply finalizer for Management object
Kshatrix Aug 8, 2024
7675a90
Split Management reconcile into Update and Delete
Kshatrix Aug 8, 2024
791b99c
Update README.md
eromanova Aug 8, 2024
6050bc9
Fix panic in case no custom config provided
eromanova Aug 8, 2024
f330605
Merge pull request #165 from Mirantis/mgmt
Kshatrix Aug 8, 2024
f1ff9b4
Reuse last HMC values on dev-apply
eromanova Aug 8, 2024
450ea2b
Bump github.com/onsi/ginkgo/v2 from 2.19.1 to 2.20.0
dependabot[bot] Aug 8, 2024
2023916
Bump github.com/cert-manager/cert-manager from 1.15.1 to 1.15.2
dependabot[bot] Aug 8, 2024
f547737
Update dev docs with troubleshooting note
squizzi Aug 8, 2024
5d9c5eb
Open port 9443 (k0s join API) for all controllers
a13x5 Aug 8, 2024
046a3f9
Merge pull request #169 from Mirantis/dependabot/go_modules/github.co…
Kshatrix Aug 9, 2024
7b68e16
Merge pull request #170 from Mirantis/dependabot/go_modules/github.co…
Kshatrix Aug 9, 2024
5e978c0
Merge pull request #172 from a13x5/sg-fix
Kshatrix Aug 9, 2024
f14f26d
Merge pull request #171 from squizzi/patch-1
Kshatrix Aug 9, 2024
4072f33
Merge pull request #166 from eromanova/fix-dev-apply
Kshatrix Aug 9, 2024
f4800c0
Merge pull request #162 from eromanova/helm-values-override-fix
Kshatrix Aug 9, 2024
4b69816
Reconcile Management removal
Kshatrix Aug 9, 2024
261267c
Remove ownerreference from mgmt HelmReleases
Kshatrix Aug 9, 2024
3a4e751
Suspending HMC helm release before deletion
Kshatrix Aug 9, 2024
3fa185a
Query HelmReleaess by label instead of components
Kshatrix Aug 9, 2024
2b69a01
Make root volume size configurable
a13x5 Aug 9, 2024
3ad8bfa
Watch only HMC managed objects in flux source controller
Kshatrix Aug 12, 2024
68f588a
Update template docs mentioning HMC labels
Kshatrix Aug 12, 2024
efb96e6
Bump github.com/docker/docker in the go_modules group
dependabot[bot] Aug 12, 2024
fc66273
Merge pull request #183 from Mirantis/dependabot/go_modules/go_module…
Kshatrix Aug 12, 2024
d0b33ef
Merge pull request #182 from Mirantis/source-label
Kshatrix Aug 12, 2024
1efdebc
Cleanup HelmCharts and HelmrRepositories managed by HMC
Kshatrix Aug 11, 2024
3f02f37
Label default HelmRepository as managed by HMC
Kshatrix Aug 12, 2024
2129cea
Merge pull request #176 from Mirantis/cleanup
Kshatrix Aug 12, 2024
2f52e0a
Add bastion configuration for AWS templates
a13x5 Aug 9, 2024
c656df5
Fix permissions for worker nodes
a13x5 Aug 12, 2024
bcc3312
Merge pull request #185 from a13x5/permission-fix
Kshatrix Aug 13, 2024
3a94b83
Merge pull request #180 from a13x5/rootvolumesize-config
Kshatrix Aug 13, 2024
7e3db30
Merge pull request #179 from a13x5/bastion-cfg
Kshatrix Aug 13, 2024
c60dbb6
Validate Deployment objects
eromanova Aug 8, 2024
ae6f385
Bump k0smotron version to v1.0.2
Kshatrix Aug 6, 2024
7ba3812
Remove hostname-override from templates
Kshatrix Aug 6, 2024
9643757
Bump AWS ccm image to v1.30.3
eromanova Aug 13, 2024
0fcac85
Merge pull request #127 from Mirantis/k0smotron-bump
Kshatrix Aug 13, 2024
d0badb7
Refactor HMC values
eromanova Aug 9, 2024
edbedd0
Enable leader election by default
eromanova Aug 13, 2024
182b2a4
Automatically create Management objects only once
eromanova Aug 12, 2024
ddc7e55
Merge pull request #184 from eromanova/mgmt-removal
Kshatrix Aug 13, 2024
a8296f4
Apply Management defaults by the admission controller
eromanova Aug 13, 2024
b563347
Merge pull request #186 from eromanova/mgmt-default
Kshatrix Aug 13, 2024
ba21b3f
Ignore k8s.io/api dependencies update
Kshatrix Aug 14, 2024
cb0a701
Merge pull request #188 from Mirantis/ignore
Kshatrix Aug 14, 2024
7b04cdd
Bump golangci-lint to v1.60.1
Kshatrix Aug 15, 2024
3a155fa
Merge pull request #191 from Mirantis/lint
Kshatrix Aug 15, 2024
cb949f4
Bump helm.sh/helm/v3 from 3.15.3 to 3.15.4
dependabot[bot] Aug 15, 2024
5132cb4
Merge pull request #189 from Mirantis/dependabot/go_modules/helm.sh/h…
Kshatrix Aug 15, 2024
c025c38
Don't keep created CRDs of cert-manager
Kshatrix Aug 15, 2024
5489e5b
Merge pull request #167 from eromanova/validation
Kshatrix Aug 15, 2024
5fcbcbe
Merge pull request #193 from Mirantis/cert-cleanup
Kshatrix Aug 15, 2024
71ebb7c
Add HMC cleanup docs
Kshatrix Aug 15, 2024
7ae77e7
Merge pull request #195 from Mirantis/cleanup-docs
Kshatrix Aug 15, 2024
6851a5a
Automatic AMI lookup parameters
a13x5 Aug 15, 2024
734d6fb
Bump github.com/fluxcd/pkg/runtime from 0.47.1 to 0.49.0
dependabot[bot] Aug 15, 2024
7113874
Merge pull request #199 from Mirantis/dependabot/go_modules/github.co…
Kshatrix Aug 16, 2024
97ae39b
Merge pull request #198 from a13x5/ami-lookup
Kshatrix Aug 16, 2024
dfba7a8
Bump github.com/cert-manager/cert-manager from 1.15.2 to 1.15.3
dependabot[bot] Aug 16, 2024
fe3576c
Merge pull request #200 from Mirantis/dependabot/go_modules/github.co…
Kshatrix Aug 16, 2024
0cb7b14
Cert Manager and Nginx install successfully on target cluster
wahabmk Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 2 additions & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ updates:
interval: daily
open-pull-requests-limit: 5
ignore:
- dependency-name: k8s.io/api
- dependency-name: k8s.io/apiextensions-apiserver
- dependency-name: k8s.io/apimachinery
- dependency-name: k8s.io/client-go
Expand All @@ -14,4 +15,4 @@ updates:
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 5
open-pull-requests-limit: 5
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
cache-to: type=gha,mode=max

- name: Prepare HMC chart
run: IMG="ghcr.io/mirantis/hmc/controller:${{ github.ref_name }}" make hmc-chart-release
run: VERSION="${{ github.ref_name }}" make hmc-chart-release
- name: Push charts to GHCR
run: REGISTRY_REPO="oci://ghcr.io/mirantis/hmc/charts" make helm-push

Expand Down
71 changes: 14 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,21 @@ help: ## Display this help.
##@ Development

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
manifests: controller-gen ## Generate CustomResourceDefinition objects.
$(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=templates/hmc/templates/crds

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

.PHONY: hmc-chart-generate
hmc-chart-generate: kustomize helmify yq ## Generate hmc helm chart
rm -rf templates/hmc/values.yaml templates/hmc/templates/*.yaml
$(KUSTOMIZE) build config/default | $(HELMIFY) templates/hmc
$(YQ) eval -iN '' templates/hmc/values.yaml config/default/hmc_values.yaml

.PHONY: set-hmc-version
set-hmc-version:
set-hmc-version: yq
$(YQ) eval '.version = "$(VERSION)"' -i templates/hmc/Chart.yaml
$(YQ) eval '.version = "$(VERSION)"' -i templates/hmc-templates/Chart.yaml
$(YQ) eval '.image.tag = "$(VERSION)"' -i templates/hmc/values.yaml

.PHONY: hmc-chart-release
hmc-chart-release: kustomize helmify yq set-hmc-version templates-generate ## Generate hmc helm chart
rm -rf templates/hmc/values.yaml templates/hmc/templates/*.yaml
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | $(HELMIFY) templates/hmc
$(YQ) eval -iN '' templates/hmc/values.yaml config/default/hmc_values.yaml
hmc-chart-release: set-hmc-version templates-generate ## Generate hmc helm chart

.PHONY: hmc-dist-release
hmc-dist-release: $(HELM) $(YQ)
Expand All @@ -94,7 +85,7 @@ templates-generate:
@hack/templates.sh

.PHONY: generate-all
generate-all: generate manifests hmc-chart-generate templates-generate add-license
generate-all: generate manifests templates-generate add-license

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand All @@ -119,11 +110,11 @@ test-e2e:

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

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

.PHONY: add-license
add-license: addlicense
Expand Down Expand Up @@ -193,12 +184,6 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
- $(CONTAINER_TOOL) buildx rm project-v3-builder
rm Dockerfile.cross

.PHONY: build-installer
build-installer: generate-all kustomize ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default > dist/install.yaml

##@ Deployment

KIND_CLUSTER_NAME ?= hmc-dev
Expand Down Expand Up @@ -244,26 +229,16 @@ registry-undeploy:

.PHONY: hmc-deploy
hmc-deploy: helm
$(HELM) dependency update templates/hmc
$(HELM) upgrade --values $(HMC_VALUES) --install --create-namespace hmc templates/hmc -n $(NAMESPACE)

.PHONY: deploy
deploy: generate-all kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -

.PHONY: undeploy
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
$(HELM) upgrade --values $(HMC_VALUES) --reuse-values --install --create-namespace hmc templates/hmc -n $(NAMESPACE)

.PHONY: dev-deploy
dev-deploy: hmc-chart-generate ## Deploy HMC helm chart to the K8s cluster specified in ~/.kube/config.
dev-deploy: ## Deploy HMC helm chart to the K8s cluster specified in ~/.kube/config.
make hmc-deploy HMC_VALUES=config/dev/hmc_values.yaml
$(KUBECTL) rollout restart -n $(NAMESPACE) deployment/hmc-controller-manager

.PHONY: dev-undeploy
dev-undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/dev | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
dev-undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(HELM) delete -n $(NAMESPACE) hmc

.PHONY: helm-push
helm-push: helm-package
Expand All @@ -289,16 +264,12 @@ dev-push: docker-build helm-push
dev-templates: templates-generate
$(KUBECTL) -n $(NAMESPACE) apply -f templates/hmc-templates/files/templates

.PHONY: dev-management
dev-management: yq
$(YQ) '.spec.core.hmc.config += (load("config/dev/hmc_values.yaml"))' config/dev/management.yaml | $(KUBECTL) -n $(NAMESPACE) apply -f -

.PHONY: dev-aws
dev-aws: yq
@$(YQ) e ".data.credentials = \"${AWS_CREDENTIALS}\"" config/dev/awscredentials.yaml | $(KUBECTL) -n $(NAMESPACE) apply -f -

.PHONY: dev-apply
dev-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates dev-management dev-aws
dev-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates dev-aws

.PHONY: dev-destroy
dev-destroy: kind-undeploy registry-undeploy
Expand Down Expand Up @@ -333,36 +304,27 @@ FLUX_HELM_CRD ?= $(EXTERNAL_CRD_DIR)/helm-$(FLUX_HELM_VERSION).yaml

## Tool Binaries
KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
HELM ?= $(LOCALBIN)/helm-$(HELM_VERSION)
HELMIFY ?= $(LOCALBIN)/helmify-$(HELMIFY_VERSION)
KIND ?= $(LOCALBIN)/kind-$(KIND_VERSION)
YQ ?= $(LOCALBIN)/yq-$(YQ_VERSION)
CLUSTERAWSADM ?= $(LOCALBIN)/clusterawsadm
CLUSTERCTL ?= $(LOCALBIN)/clusterctl
ADDLICENSE ?= $(LOCALBIN)/addlicense-$(ADDLICENSE_VERSION)

## Tool Versions
KUSTOMIZE_VERSION ?= v5.3.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_VERSION ?= release-0.17
GOLANGCI_LINT_VERSION ?= v1.57.2
GOLANGCI_LINT_VERSION ?= v1.60.1
HELM_VERSION ?= v3.15.1
HELMIFY_VERSION ?= v0.4.13
KIND_VERSION ?= v0.23.0
YQ_VERSION ?= v4.44.2
CLUSTERAWSADM_VERSION ?= v2.5.2
CLUSTERCTL_VERSION ?= v1.7.3
ADDLICENSE_VERSION ?= v1.1.1

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): | $(LOCALBIN)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): | $(LOCALBIN)
Expand All @@ -385,11 +347,6 @@ $(HELM): | $(LOCALBIN)
rm -f $(LOCALBIN)/helm-*
curl -s $(HELM_INSTALL_SCRIPT) | USE_SUDO=false HELM_INSTALL_DIR=$(LOCALBIN) DESIRED_VERSION=$(HELM_VERSION) BINARY_NAME=helm-$(HELM_VERSION) PATH="$(LOCALBIN):$(PATH)" bash

.PHONY: helmify
helmify: $(HELMIFY) ## Download helmify locally if necessary.
$(HELMIFY): | $(LOCALBIN)
$(call go-install-tool,$(HELMIFY),github.com/arttor/helmify/cmd/helmify,${HELMIFY_VERSION})

$(FLUX_HELM_CRD): $(EXTERNAL_CRD_DIR)
rm -f $(FLUX_HELM_CRD)
curl -s https://raw.githubusercontent.com/fluxcd/helm-controller/$(FLUX_HELM_VERSION)/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml > $(FLUX_HELM_CRD)
Expand Down
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ or install using `helm`

Then follow the [Deploy a managed cluster](#deploy-a-managed-cluster) guide to create a managed cluster.

> Note: The HMC installation using Kubernetes manifests does not allow customization of the deployment. To apply a custom HMC configuration, install HMC using the Helm chart.
> deployment. If the custom HMC configuration should be applied, install HMC using
> the Helm chart.

### Development guide

See [Install HMC for development purposes](docs/dev.md#hmc-installation-for-development).
Expand Down Expand Up @@ -78,11 +82,11 @@ configuration:
* Create `management.yaml` file and configure core components and providers.
See [Management API](api/v1alpha1/management_types.go).

* Specify `--create-management=false` controllerManager argument and install HMC:
* Specify `--create-management=false` controller argument and install HMC:

If installing using `helm` add the following parameter to the `helm install` command:

`--set="controllerManager.manager.args={--create-management=false}"`
`--set="controller.createManagement=false"`

* Create `hmc-system/hmc` `Management` object after HMC installation:

Expand Down Expand Up @@ -232,3 +236,19 @@ spec:
type: Ready
observedGeneration: 1
```

## Cleanup

1. Remove the Management object:

`kubectl delete management.hmc hmc -n hmc-system`

> Note: make sure you have no HMC Deployment objects left in the cluster prior to Management deletion

2. Remove the `hmc` Helm release:

`helm uninstall hmc -n hmc-system`

3. Remove the `hmc-system` namespace:

`kubectl delete ns hmc-system`
3 changes: 2 additions & 1 deletion api/v1alpha1/deployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
const (
DeploymentFinalizer = "hmc.mirantis.com/deployment"

HMCManagedLabelKey = "hmc.mirantis.com/managed"
HMCManagedLabelKey = "hmc.mirantis.com/managed"
HMCManagedLabelValue = "true"
)

const (
Expand Down
25 changes: 24 additions & 1 deletion api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@ const (

ManagementName = "hmc"
ManagementNamespace = "hmc-system"

ManagementFinalizer = "hmc.mirantis.com/management"
)

var DefaultCoreConfiguration = Core{
HMC: Component{
Template: DefaultCoreHMCTemplate,
},
CAPI: Component{
Template: DefaultCoreCAPITemplate,
},
}

// ManagementSpec defines the desired state of Management
type ManagementSpec struct {
// Core holds the core Management components that are mandatory.
Expand Down Expand Up @@ -68,7 +79,19 @@ func (in *Component) HelmValues() (values map[string]interface{}, err error) {
return values, err
}

func (m *ManagementSpec) SetDefaults() {
func (in *Component) HelmReleaseName() string {
return in.Template
}

func (m *ManagementSpec) SetDefaults() bool {
if m.Core != nil {
return false
}
m.Core = &DefaultCoreConfiguration
return true
}

func (m *ManagementSpec) SetProvidersDefaults() {
m.Providers = []Component{
{
Template: "k0smotron",
Expand Down
Loading
Loading