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

get config form ServiceCR and remove MonitoringOptions in whizard-config #425

Merged
merged 1 commit into from
Jan 12, 2024
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ docker-build-monitoring-block-manager:
##@ Deployment

install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
$(KUSTOMIZE) build config/crd | kubectl apply --server-side -f -

uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -

deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${CONTROLLER_MANAGER_IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
$(KUSTOMIZE) build config/default | kubectl apply --server-side -f -

undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
Expand Down
50 changes: 16 additions & 34 deletions cmd/controller-manager/app/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ package app
import (
"context"

"github.com/kubesphere/whizard/cmd/controller-manager/app/options"
"github.com/kubesphere/whizard/pkg/client/k8s"
"github.com/kubesphere/whizard/pkg/controllers/monitoring"
"github.com/kubesphere/whizard/pkg/informers"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

func addControllers(mgr manager.Manager, client k8s.Client, informerFactory informers.InformerFactory,
cmOptions *options.ControllerManagerOptions, ctx context.Context) error {
func addControllers(mgr manager.Manager, client k8s.Client, ctx context.Context) error {

if err := (&monitoring.GatewayReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions.Gateway,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Gateway controller: %v", err)
return err
Expand All @@ -28,7 +24,6 @@ func addControllers(mgr manager.Manager, client k8s.Client, informerFactory info
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions.QueryFrontend,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Query Frontend controller: %v", err)
return err
Expand All @@ -38,7 +33,6 @@ func addControllers(mgr manager.Manager, client k8s.Client, informerFactory info
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Query controller: %v", err)
return err
Expand All @@ -48,62 +42,51 @@ func addControllers(mgr manager.Manager, client k8s.Client, informerFactory info
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Router controller: %v", err)
return err
}

if err := (&monitoring.StoreReconciler{
DefaulterValidator: monitoring.CreateStoreDefaulterValidator(cmOptions.MonitoringOptions.Store),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions.Store,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Store controller: %v", err)
return err
}

if err := (&monitoring.CompactorReconciler{
DefaulterValidator: monitoring.CreateCompactorDefaulterValidator(cmOptions.MonitoringOptions.Compactor),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions.Compactor,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Compactor controller: %v", err)
return err
}

if err := (&monitoring.IngesterReconciler{
DefaulterValidator: monitoring.CreateIngesterDefaulterValidator(cmOptions.MonitoringOptions.Ingester),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions.Ingester,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Ingester controller: %v", err)
return err
}

if err := (&monitoring.RulerReconciler{
DefaulterValidator: monitoring.CreateRulerDefaulterValidator(cmOptions.MonitoringOptions.Ruler),
Option: cmOptions.MonitoringOptions.Ruler,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Ruler controller: %v", err)
return err
}

if err := (&monitoring.TenantReconciler{
DefaulterValidator: monitoring.CreateTenantDefaulterValidator(*cmOptions.MonitoringOptions),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Tenant controller: %v", err)
return err
Expand All @@ -113,7 +96,6 @@ func addControllers(mgr manager.Manager, client k8s.Client, informerFactory info
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Context: ctx,
Options: cmOptions.MonitoringOptions.Storage,
}).SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to create Storage controller: %v", err)
return err
Expand Down
22 changes: 4 additions & 18 deletions cmd/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import (

"github.com/kubesphere/whizard/pkg/client/k8s"
"github.com/kubesphere/whizard/pkg/controllers/config"
monitoring "github.com/kubesphere/whizard/pkg/controllers/monitoring/options"
)

type ControllerManagerOptions struct {
KubernetesOptions *k8s.KubernetesOptions
MonitoringOptions *monitoring.Options

LeaderElect bool
LeaderElection *leaderelection.LeaderElectionConfig
WebhookCertDir string

MetricsBindAddress string
HealthProbeBindAddress string
Expand All @@ -30,15 +27,13 @@ type ControllerManagerOptions struct {
func NewControllerManagerOptions() *ControllerManagerOptions {
return &ControllerManagerOptions{
KubernetesOptions: k8s.NewKubernetesOptions(),
MonitoringOptions: monitoring.NewOptions(),

LeaderElection: &leaderelection.LeaderElectionConfig{
LeaseDuration: 30 * time.Second,
RenewDeadline: 15 * time.Second,
RetryPeriod: 5 * time.Second,
},
LeaderElect: false,
WebhookCertDir: "",
LeaderElect: false,

MetricsBindAddress: ":8080",
HealthProbeBindAddress: ":8081",
Expand All @@ -48,19 +43,13 @@ func NewControllerManagerOptions() *ControllerManagerOptions {
func (s *ControllerManagerOptions) Flags() cliflag.NamedFlagSets {
fss := cliflag.NamedFlagSets{}
s.KubernetesOptions.AddFlags(fss.FlagSet("kubernetes"), s.KubernetesOptions)
s.MonitoringOptions.AddFlags(fss.FlagSet("monitoring"), s.MonitoringOptions)

fs := fss.FlagSet("leaderelection")
s.bindLeaderElectionFlags(s.LeaderElection, fs)

fs.BoolVar(&s.LeaderElect, "leader-elect", s.LeaderElect, ""+
"Whether to enable leader election. This field should be enabled when controller manager"+
"deployed with multiple replicas.")

fs.StringVar(&s.WebhookCertDir, "webhook-cert-dir", s.WebhookCertDir, ""+
"Certificate directory used to setup webhooks, need tls.crt and tls.key placed inside."+
"if not set, webhook server would look up the server key and certificate in"+
"{TempDir}/k8s-webhook-server/serving-certs")
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")

kfs := fss.FlagSet("klog")
local := flag.NewFlagSet("klog", flag.ExitOnError)
Expand All @@ -80,7 +69,7 @@ func (s *ControllerManagerOptions) Flags() cliflag.NamedFlagSets {
func (s *ControllerManagerOptions) Validate() []error {
var errs []error
errs = append(errs, s.KubernetesOptions.Validate()...)
errs = append(errs, s.MonitoringOptions.Validate()...)

return errs
}

Expand All @@ -107,7 +96,4 @@ func (s *ControllerManagerOptions) MergeConfig(cfg *config.Config) {
cfg.KubernetesOptions.ApplyTo(s.KubernetesOptions)
}

if cfg.MonitoringOptions != nil {
cfg.MonitoringOptions.ApplyTo(s.MonitoringOptions)
}
}
10 changes: 0 additions & 10 deletions cmd/controller-manager/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

"github.com/kubesphere/whizard/cmd/controller-manager/app/options"
"github.com/kubesphere/whizard/pkg/apis"
Expand All @@ -39,9 +38,6 @@ func NewControllerManagerCommand() *cobra.Command {
conf.KubernetesOptions.ApplyTo(s.KubernetesOptions)
}

if conf.MonitoringOptions != nil {
conf.MonitoringOptions.ApplyTo(s.MonitoringOptions)
}
} else {
klog.Fatal("Failed to load configuration from disk", err)
}
Expand Down Expand Up @@ -142,10 +138,6 @@ func run(s *options.ControllerManagerOptions, ctx context.Context) error {
Metrics: metricsserver.Options{
BindAddress: s.MetricsBindAddress,
},
WebhookServer: webhook.NewServer(webhook.Options{
CertDir: s.WebhookCertDir,
Port: 8443,
}),
}

if s.LeaderElect {
Expand Down Expand Up @@ -173,8 +165,6 @@ func run(s *options.ControllerManagerOptions, ctx context.Context) error {

if err = addControllers(mgr,
kubernetesClient,
informerFactory,
s,
ctx); err != nil {
return fmt.Errorf("unable to register controllers to the manager: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/monitoring.whizard.io_gateways.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
versions:
- additionalPrinterColumns:
- description: The number of desired replicas
jsonPath: .spec.Node
jsonPath: .spec.replicas
name: Replicas
type: integer
- description: The nodePort of Gateway service
Expand Down
56 changes: 56 additions & 0 deletions config/crd/bases/monitoring.whizard.io_ingesters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,62 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
ingesterTsdbCleanup:
properties:
image:
description: Image is the envoy image with tag/version
type: string
resources:
description: Define resources requests and limits for sidecar
container.
properties:
claims:
description: "Claims lists the names of resources, defined
in spec.resourceClaims, that are used by this container.
\n This is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable. It can only be
set for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
name:
description: Name must match the name of one entry in
pod.spec.resourceClaims of the Pod where this field
is used. It makes that resource available inside a
container.
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. Requests cannot exceed
Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
type: object
localTsdbRetention:
description: LocalTsdbRetention configs how long to retain raw samples
on local storage.
Expand Down
Loading