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

Merge dev to main #138

Merged
merged 5 commits into from
Nov 29, 2023
Merged
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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ KIND := $(TOOLS_BIN_DIR)/kind
KUBECTL := $(TOOLS_BIN_DIR)/kubectl

GOLANGCI_LINT_VERSION := "v1.52.2"
CLUSTERCTL_VERSION := "v1.5.3"
CLUSTERCTL_VERSION := "v1.6.0-rc.1"

$(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 Down Expand Up @@ -195,6 +195,12 @@ create-cluster: $(KIND) $(CLUSTERCTL) $(KUBECTL) $(ENVSUBST) ## Create a new kin
@echo wait for capd-system pod
$(KUBECTL) wait --for=condition=Available deployment/capd-controller-manager -n capd-system --timeout=$(TIMEOUT)

@echo wait for capi-kubeadm-bootstrap-system pod
$(KUBECTL) wait --for=condition=Available deployment/capi-kubeadm-bootstrap-controller-manager -n capi-kubeadm-bootstrap-system --timeout=$(TIMEOUT)

@echo wait for capi-kubeadm-control-plane-system pod
$(KUBECTL) wait --for=condition=Available deployment/capi-kubeadm-control-plane-controller-manager -n capi-kubeadm-control-plane-system --timeout=$(TIMEOUT)

@echo "Create a workload cluster"
$(KUBECTL) apply -f $(KIND_CLUSTER_YAML)

Expand Down
81 changes: 63 additions & 18 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ import (
"k8s.io/klog/v2"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

libsveltosv1alpha1 "github.com/projectsveltos/libsveltos/api/v1alpha1"
"github.com/projectsveltos/libsveltos/lib/crd"
Expand All @@ -64,6 +68,10 @@ var (
reportMode controllers.ReportMode
tmpReportMode int
reloaderReportCollectionTime int
restConfigQPS float32
restConfigBurst int
webhookPort int
syncPeriod time.Duration
)

const (
Expand All @@ -90,12 +98,26 @@ func main() {

ctrl.SetLogger(klog.Background())

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
ctrlOptions := ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
})
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
WebhookServer: webhook.NewServer(
webhook.Options{
Port: webhookPort,
}),
Cache: cache.Options{
SyncPeriod: &syncPeriod,
},
}

restConfig := ctrl.GetConfigOrDie()
restConfig.QPS = restConfigQPS
restConfig.Burst = restConfigBurst

mgr, err := ctrl.NewManager(restConfig, ctrlOptions)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
Expand All @@ -114,20 +136,8 @@ func main() {
controllers.SetManagementRecorder(mgr.GetEventRecorderFor("notification-recorder"))

var clusterHealthCheckController controller.Controller
clusterHealthCheckReconciler := &controllers.ClusterHealthCheckReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
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),
ClusterLabels: make(map[corev1.ObjectReference]map[string]string),
HealthCheckMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
CHCToHealthCheckMap: make(map[types.NamespacedName]*libsveltosset.Set),
}
clusterHealthCheckReconciler := getClusterHealthCheckReconciler(mgr)
clusterHealthCheckReconciler.Deployer = d

clusterHealthCheckController, err = clusterHealthCheckReconciler.SetupWithManager(mgr)
if err != nil {
Expand Down Expand Up @@ -195,6 +205,25 @@ func initFlags(fs *pflag.FlagSet) {

fs.IntVar(&concurrentReconciles, "concurrent-reconciles", defaultReconcilers,
"concurrent reconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 10")

const defautlRestConfigQPS = 20
fs.Float32Var(&restConfigQPS, "kube-api-qps", defautlRestConfigQPS,
fmt.Sprintf("Maximum queries per second from the controller client to the Kubernetes API server. Defaults to %d",
defautlRestConfigQPS))

const defaultRestConfigBurst = 30
fs.IntVar(&restConfigBurst, "kube-api-burst", defaultRestConfigBurst,
fmt.Sprintf("Maximum number of queries that should be allowed in one burst from the controller client to the Kubernetes API server. Default %d",
defaultRestConfigBurst))

const defaultWebhookPort = 9443
fs.IntVar(&webhookPort, "webhook-port", defaultWebhookPort,
"Webhook Server port")

const defaultSyncPeriod = 10
fs.DurationVar(&syncPeriod, "sync-period", defaultSyncPeriod*time.Minute,
fmt.Sprintf("The minimum interval at which watched resources are reconciled (e.g. 15m). Default: %d minutes",
defaultSyncPeriod))
}

func setupChecks(mgr ctrl.Manager) {
Expand Down Expand Up @@ -267,3 +296,19 @@ func capiWatchers(ctx context.Context, mgr ctrl.Manager, clusterHealthCheckRecon
}
}
}

func getClusterHealthCheckReconciler(mgr manager.Manager) *controllers.ClusterHealthCheckReconciler {
return &controllers.ClusterHealthCheckReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ConcurrentReconciles: concurrentReconciles,
Mux: sync.Mutex{},
ShardKey: shardKey,
ClusterMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
CHCToClusterMap: make(map[types.NamespacedName]*libsveltosset.Set),
ClusterHealthChecks: make(map[corev1.ObjectReference]libsveltosv1alpha1.Selector),
ClusterLabels: make(map[corev1.ObjectReference]map[string]string),
HealthCheckMap: make(map[corev1.ObjectReference]*libsveltosset.Set),
CHCToHealthCheckMap: make(map[types.NamespacedName]*libsveltosset.Set),
}
}
6 changes: 3 additions & 3 deletions controllers/healthcheckreport_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func removeHealthCheckReports(ctx context.Context, c client.Client, healthCheck

listOptions := []client.ListOption{
client.MatchingLabels{
libsveltosv1alpha1.HealthCheckLabelName: healthCheck.Name,
libsveltosv1alpha1.HealthCheckNameLabel: healthCheck.Name,
},
}

Expand Down Expand Up @@ -198,7 +198,7 @@ func deleteHealthCheckReport(ctx context.Context, c client.Client, cluster *core
return errors.New(malformedLabelError)
}

healthCheckName, ok := healthCheckReport.Labels[libsveltosv1alpha1.HealthCheckLabelName]
healthCheckName, ok := healthCheckReport.Labels[libsveltosv1alpha1.HealthCheckNameLabel]
if !ok {
logger.V(logs.LogInfo).Info(missingLabelError)
return errors.New(missingLabelError)
Expand Down Expand Up @@ -233,7 +233,7 @@ func updateHealthCheckReport(ctx context.Context, c client.Client, cluster *core
return errors.New(malformedLabelError)
}

healthCheckName, ok := healthCheckReport.Labels[libsveltosv1alpha1.HealthCheckLabelName]
healthCheckName, ok := healthCheckReport.Labels[libsveltosv1alpha1.HealthCheckNameLabel]
if !ok {
logger.V(logs.LogInfo).Info(missingLabelError)
return errors.New(missingLabelError)
Expand Down
2 changes: 1 addition & 1 deletion controllers/healthcheckreport_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func validateHealthCheckReports(healthCheckName string, cluster *clusterv1.Clust
By("Spec ClusterNamespace and ClusterName not set")
return false
}
v, ok := currentHealthCheckReport.Labels[libsveltosv1alpha1.HealthCheckLabelName]
v, ok := currentHealthCheckReport.Labels[libsveltosv1alpha1.HealthCheckNameLabel]
return ok && v == healthCheckName
}, timeout, pollingInterval).Should(BeTrue())
}
2 changes: 1 addition & 1 deletion controllers/suite_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func getHealthCheckReport(healthCheckName, clusterNamespace, clusterName string)
ObjectMeta: metav1.ObjectMeta{
Name: randomString(),
Labels: map[string]string{
libsveltosv1alpha1.HealthCheckLabelName: healthCheckName,
libsveltosv1alpha1.HealthCheckNameLabel: healthCheckName,
},
},
Spec: libsveltosv1alpha1.HealthCheckReportSpec{
Expand Down
76 changes: 39 additions & 37 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ require (
github.com/gdexlab/go-render v1.0.1
github.com/go-logr/logr v1.3.0
github.com/jbogarin/go-cisco-webex-teams v0.4.3
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/gomega v1.29.0
github.com/onsi/ginkgo/v2 v2.13.1
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.9.1
github.com/projectsveltos/addon-controller v0.19.1-0.20231030114831-0507118028db
github.com/projectsveltos/libsveltos v0.19.1-0.20231029140049-048f7f2b4d99
github.com/projectsveltos/addon-controller v0.20.1-0.20231129100117-bfbd565b5b64
github.com/projectsveltos/libsveltos v0.20.1-0.20231129081648-ef5be475b0c0
github.com/prometheus/client_golang v1.17.0
github.com/slack-go/slack v0.12.3
github.com/spf13/pflag v1.0.5
golang.org/x/text v0.13.0
k8s.io/api v0.28.2
k8s.io/apiextensions-apiserver v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.2
k8s.io/component-base v0.28.2
golang.org/x/text v0.14.0
k8s.io/api v0.28.4
k8s.io/apiextensions-apiserver v0.28.4
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
k8s.io/component-base v0.28.4
k8s.io/klog/v2 v2.100.1
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/cluster-api v1.5.3
sigs.k8s.io/controller-runtime v0.15.1
sigs.k8s.io/cluster-api v1.6.0-rc.1
sigs.k8s.io/controller-runtime v0.16.3
)

require (
Expand All @@ -40,26 +40,26 @@ require (
github.com/Microsoft/hcsshim v0.11.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/containerd/containerd v1.7.6 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/dariubs/percent v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/cli v24.0.6+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fluxcd/pkg/apis/acl v0.1.0 // indirect
github.com/fluxcd/pkg/apis/meta v1.1.2 // indirect
github.com/fluxcd/pkg/http/fetch v0.6.0 // indirect
Expand Down Expand Up @@ -89,7 +89,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
Expand All @@ -112,7 +112,7 @@ require (
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand Down Expand Up @@ -142,44 +142,46 @@ require (
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/yuin/gopher-lua v1.1.0 // indirect
github.com/zeebo/blake3 v0.1.1 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.opentelemetry.io/otel v1.20.0 // indirect
go.opentelemetry.io/otel/metric v1.20.0 // indirect
go.opentelemetry.io/otel/trace v1.20.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/evanphx/json-patch.v5 v5.6.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
helm.sh/helm/v3 v3.13.1 // indirect
k8s.io/apiserver v0.28.2 // indirect
k8s.io/cli-runtime v0.28.2 // indirect
k8s.io/apiserver v0.28.4 // indirect
k8s.io/cli-runtime v0.28.4 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubectl v0.28.2 // indirect
k8s.io/kubectl v0.28.4 // indirect
oras.land/oras-go v1.2.4 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.15.0 // indirect
sigs.k8s.io/kustomize/kyaml v0.15.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

// Replace digest lib to master to gather access to BLAKE3.
Expand Down
Loading