Skip to content

Commit

Permalink
Merge pull request #134 from gianlucam76/main
Browse files Browse the repository at this point in the history
Merge dev to main
  • Loading branch information
gianlucam76 authored Oct 30, 2023
2 parents 0ad3667 + 6c21750 commit be34603
Show file tree
Hide file tree
Showing 28 changed files with 617 additions and 1,889 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
- name: checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.0
go-version: 1.20.8
- name: Build
run: make build
- name: FMT
Expand All @@ -35,9 +35,9 @@ jobs:
- name: checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.0
go-version: 1.20.8
- name: ut
run: make test
env:
Expand All @@ -48,10 +48,23 @@ jobs:
- name: checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.20.0
go-version: 1.20.8
- name: fv
run: make create-cluster fv
env:
FV: true
FV-SHARDING:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.8
- name: fv
run: make create-cluster fv-sharding
env:
FV: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ manager_image_patch.yaml-e
manager_pull_policy.yaml-e

version.txt

ac-deployment-shard.yaml
tmp-ac-deployment-shard.yaml
32 changes: 19 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-rele
export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= main

# Get cluster-api version and build ldflags
clusterapi := $(shell go list -m sigs.k8s.io/cluster-api)
clusterapi_version := $(lastword ., ,$(clusterapi))
clusterapi_version_tuple := $(subst ., ,$(clusterapi_version:v%=%))
clusterapi_major := $(word 1,$(clusterapi_version_tuple))
clusterapi_minor := $(word 2,$(clusterapi_version_tuple))
clusterapi_patch := $(word 3,$(clusterapi_version_tuple))
CLUSTERAPI_LDFLAGS := "-X 'sigs.k8s.io/cluster-api/version.gitMajor=$(clusterapi_major)' -X 'sigs.k8s.io/cluster-api/version.gitMinor=$(clusterapi_minor)' -X 'sigs.k8s.io/cluster-api/version.gitVersion=$(clusterapi_version)'"

.PHONY: all
all: build

Expand Down Expand Up @@ -78,6 +69,7 @@ KIND := $(TOOLS_BIN_DIR)/kind
KUBECTL := $(TOOLS_BIN_DIR)/kubectl

GOLANGCI_LINT_VERSION := "v1.52.2"
CLUSTERCTL_VERSION := "v1.5.3"

$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
cd $(TOOLS_DIR); $(GOBUILD) -tags=tools -o $(subst $(TOOLS_DIR)/hack/tools/,,$@) sigs.k8s.io/controller-tools/cmd/controller-gen
Expand All @@ -101,7 +93,8 @@ $(KIND): $(TOOLS_DIR)/go.mod
cd $(TOOLS_DIR) && $(GOBUILD) -tags tools -o $(subst $(TOOLS_DIR)/hack/tools/,,$@) sigs.k8s.io/kind

$(CLUSTERCTL): $(TOOLS_DIR)/go.mod ## Build clusterctl binary
cd $(TOOLS_DIR); $(GOBUILD) -trimpath -ldflags $(CLUSTERAPI_LDFLAGS) -o $(subst $(TOOLS_DIR)/hack/tools/,,$@) sigs.k8s.io/cluster-api/cmd/clusterctl
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/$(CLUSTERCTL_VERSION)/clusterctl-$(OS)-$(ARCH) -o $@
chmod +x $@
mkdir -p $(HOME)/.cluster-api # create cluster api init directory, if not present

$(KUBECTL):
Expand Down Expand Up @@ -131,6 +124,7 @@ manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) $(ENVSUBST) fmt generate ## Generate W
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image
$(KUSTOMIZE) build config/default | $(ENVSUBST) > manifest/manifest.yaml
./scripts/extract_deployment.sh manifest/manifest.yaml manifest/deployment-shard.yaml

.PHONY: generate
generate: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down Expand Up @@ -186,6 +180,14 @@ kind-test: test create-cluster fv ## Build docker image; start kind cluster; loa
fv: $(GINKGO) ## Run Sveltos Controller tests using existing cluster
cd test/fv; $(GINKGO) -nodes $(NUM_NODES) --label-filter='FV' --v --trace --randomize-all

.PHONY: fv-sharding
fv-sharding: $(KUBECTL) $(GINKGO) ## Run Sveltos Controller tests using existing cluster
$(KUBECTL) patch cluster clusterapi-workload -n default --type json -p '[{ "op": "add", "path": "/metadata/annotations/sharding.projectsveltos.io~1key", "value": "shard1" }]'
sed -e "s/{{.SHARD}}/shard1/g" manifest/deployment-shard.yaml > test/hc-deployment-shard.yaml
$(KUBECTL) apply -f test/hc-deployment-shard.yaml
rm -f test/hc-deployment-shard.yaml
cd test/fv; $(GINKGO) -nodes $(NUM_NODES) --label-filter='FV' --v --trace --randomize-all

.PHONY: create-cluster
create-cluster: $(KIND) $(CLUSTERCTL) $(KUBECTL) $(ENVSUBST) ## Create a new kind cluster designed for development
$(MAKE) create-control-cluster
Expand Down Expand Up @@ -272,9 +274,13 @@ deploy-projectsveltos: $(KUSTOMIZE) $(KUBECTL)
# Install addon-compliance-controller
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/addon-compliance-controller/$(TAG)/manifest/manifest.yaml

# Install sveltos-manager
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/sveltos-manager/$(TAG)/manifest/manifest.yaml

# Install projectsveltos addon-controller
$(KUBECTL) apply -f https://raw.githubusercontent.com/projectsveltos/addon-controller/$(TAG)/manifest/manifest.yaml
curl https://raw.githubusercontent.com/projectsveltos/addon-controller/$(TAG)/manifest/deployment-shard.yaml -o ac-deployment-shard.yaml
sed -e "s/{{.SHARD}}/shard1/g" ac-deployment-shard.yaml > tmp-ac-deployment-shard.yaml
$(KUBECTL) apply -f tmp-ac-deployment-shard.yaml
rm ac-deployment-shard.yaml
rm tmp-ac-deployment-shard.yaml

# Install projectsveltos healthcheck-manager components
@echo 'Install projectsveltos controller-manager components'
Expand Down
11 changes: 5 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import (
var (
setupLog = ctrl.Log.WithName("setup")
metricsAddr string
enableLeaderElection bool
shardKey string
probeAddr string
workers int
concurrentReconciles int
Expand Down Expand Up @@ -95,8 +95,6 @@ func main() {
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "7964f530.projectsveltos.io",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand All @@ -122,6 +120,7 @@ func main() {
ConcurrentReconciles: concurrentReconciles,
Mux: sync.Mutex{},
Deployer: d,
ShardKey: shardKey,
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
CHCToClusterMap: make(map[types.NamespacedName]*libsveltosset.Set),
ClusterHealthChecks: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector),
Expand All @@ -139,6 +138,7 @@ func main() {
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
HealthCheckReportMode: reportMode,
ShardKey: shardKey,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "HealthCheck")
os.Exit(1)
Expand Down Expand Up @@ -187,9 +187,8 @@ func initFlags(fs *pflag.FlagSet) {
fs.StringVar(&probeAddr, "health-probe-bind-address", ":8081",
"The address the probe endpoint binds to.")

fs.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
fs.StringVar(&shardKey, "shard-key", "",
"If set, and report-mode is set to collect, this deployment will fetch only from clusters matching this shard")

fs.IntVar(&workers, "worker-number", defaultWorkers,
"Number of worker. Workers are used to verify health checks in managed clusters")
Expand Down
4 changes: 0 additions & 4 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ patchesStrategicMerge:
- manager_image_patch.yaml
- manager_pull_policy.yaml

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
#- manager_config_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- manager_webhook_patch.yaml
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ spec:
args:
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
- "--shard-key="
- "--v=5"
20 changes: 0 additions & 20 deletions config/default/manager_config_patch.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ resources:
generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- files:
- controller_manager_config.yaml
name: manager-config
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
Expand Down
1 change: 0 additions & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ spec:
- command:
- /manager
args:
- --leader-elect
image: controller:latest
name: manager
securityContext:
Expand Down
2 changes: 0 additions & 2 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ resources:
- service_account.yaml
- role.yaml
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
# Comment the following 4 lines if you want to disable
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
# which protects your /metrics endpoint.
Expand Down
37 changes: 0 additions & 37 deletions config/rbac/leader_election_role.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions config/rbac/leader_election_role_binding.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion controllers/clusterhealthcheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type ClusterHealthCheckReconciler struct {
Scheme *runtime.Scheme
ConcurrentReconciles int
Deployer deployer.DeployerInterface

ShardKey string // when set, only clusters matching the ShardKey will be reconciled
// use a Mutex to update Map as MaxConcurrentReconciles is higher than one
Mux sync.Mutex

Expand Down Expand Up @@ -182,6 +182,7 @@ func (r *ClusterHealthCheckReconciler) Reconcile(ctx context.Context, req ctrl.R
// changes.
defer func() {
if err := clusterHealthCheckScope.Close(ctx); err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to update: %v", err))
reterr = err
}
}()
Expand Down
Loading

0 comments on commit be34603

Please sign in to comment.