Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Commit

Permalink
initial health check library implementation + integration for all ext…
Browse files Browse the repository at this point in the history
…ensions
  • Loading branch information
danielfoehrKn committed Nov 29, 2019
1 parent b178cec commit 1c9b2b7
Show file tree
Hide file tree
Showing 144 changed files with 3,636 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
{
"typeMatchPrefix": "^k8s\\.io/(api|apimachinery/pkg/apis)/",
"docsURLTemplate": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}"
},
{
"typeMatchPrefix": "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config",
"docsURLTemplate": "https://github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config"
}
],
"typeDisplayNamePrefixOverrides": {
Expand Down
5 changes: 4 additions & 1 deletion controllers/extension-shoot-cert-service/cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/spf13/cobra"
componentbaseconfig "k8s.io/component-base/config"
"sigs.k8s.io/controller-runtime/pkg/manager"

certhealthcheck "github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/controller/healthcheck"
)

// NewServiceControllerCommand creates a new command that is used to start the Certificate Service controller.
Expand Down Expand Up @@ -70,9 +72,10 @@ func (o *Options) run(ctx context.Context) {
}

ctrlConfig := o.certOptions.Completed()

ctrlConfig.ApplyHealthCheckConfig(&certhealthcheck.DefaultAddOptions.HealthCheckConfig)
ctrlConfig.Apply(&controller.DefaultAddOptions.ServiceConfig)
o.controllerOptions.Completed().Apply(&controller.DefaultAddOptions.ControllerOptions)
o.healthOptions.Completed().Apply(&certhealthcheck.DefaultAddOptions.Controller)
o.reconcileOptions.Completed().Apply(&controller.DefaultAddOptions.IgnoreOperationAnnotation)

if err := o.controllerSwitches.Completed().AddToManager(mgr); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions controllers/extension-shoot-cert-service/cmd/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Options struct {
restOptions *controllercmd.RESTOptions
managerOptions *controllercmd.ManagerOptions
controllerOptions *controllercmd.ControllerOptions
healthOptions *controllercmd.ControllerOptions
controllerSwitches *controllercmd.SwitchOptions
reconcileOptions *controllercmd.ReconcilerOptions
optionAggregator controllercmd.OptionAggregator
Expand All @@ -50,6 +51,10 @@ func NewOptions() *Options {
// This is a default value.
MaxConcurrentReconciles: 5,
},
healthOptions: &controllercmd.ControllerOptions{
// This is a default value.
MaxConcurrentReconciles: 5,
},
controllerSwitches: certificateservicecmd.ControllerSwitches(),
reconcileOptions: &controllercmd.ReconcilerOptions{},
}
Expand All @@ -59,6 +64,7 @@ func NewOptions() *Options {
options.managerOptions,
options.controllerOptions,
options.certOptions,
controllercmd.PrefixOption("healthcheck-", options.healthOptions),
options.controllerSwitches,
options.reconcileOptions,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
{
"typeMatchPrefix": "^k8s\\.io/(api|apimachinery/pkg/apis)/",
"docsURLTemplate": "https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}"
},
{
"typeMatchPrefix": "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config",
"docsURLTemplate": "https://github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config"
}
],
"typeDisplayNamePrefixOverrides": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ ACME
<td>
</td>
</tr>
<tr>
<td>
<code>healthCheckConfig</code></br>
<em>
<a href="https://github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config">
github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config/v1alpha1.HealthCheckConfig
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>HealthCheckConfig</p>
</td>
</tr>
</tbody>
</table>
<h3 id="shoot-cert-service.extensions.config.gardener.cloud/v1alpha1.ACME">ACME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package config

import (
extensionhealthcheck "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -26,6 +27,8 @@ type Configuration struct {

IssuerName string
ACME ACME
// HealthCheckConfig
HealthCheckConfig *extensionhealthcheck.HealthCheckConfig
}

// ACME holds information about the ACME issuer used for the certificate service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha1

import (
extensionhealthcheckv1alpha1 "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -27,6 +28,9 @@ type Configuration struct {

IssuerName string `json:"issuerName"`
ACME ACME `json:"acme"`
// HealthCheckConfig
// +optional
HealthCheckConfig *extensionhealthcheckv1alpha1.HealthCheckConfig `json:"healthCheckConfig"`
}

// ACME holds information about the ACME issuer used for the certificate service.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions controllers/extension-shoot-cert-service/pkg/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/config/validation"
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/controller"
controllerconfig "github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/controller/config"
healthcheckcontroller "github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/controller/healthcheck"
extensionshealthcheckcontroller "github.com/gardener/gardener-extensions/pkg/controller/healthcheck"
extensionhealthcheck "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -102,5 +105,12 @@ func (c *CertificateServiceConfig) Apply(config *controllerconfig.Config) {
func ControllerSwitches() *cmd.SwitchOptions {
return cmd.NewSwitchOptions(
cmd.Switch(controller.ControllerName, controller.AddToManager),
cmd.Switch(extensionshealthcheckcontroller.ControllerName, healthcheckcontroller.AddToManager),
)
}

func (c *CertificateServiceConfig) ApplyHealthCheckConfig(config *extensionhealthcheck.HealthCheckConfig) {
if c.config.HealthCheckConfig != nil {
*config = *c.config.HealthCheckConfig
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package healthcheck

import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

gardencorev1alpha1 "github.com/gardener/gardener/pkg/apis/core/v1alpha1"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/manager"

extensionshealthcheckcontroller "github.com/gardener/gardener-extensions/pkg/controller/healthcheck"
"github.com/gardener/gardener-extensions/pkg/controller/healthcheck/general"

certv1alpha1 "github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/service/v1alpha1"
certcontroller "github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/controller"
extensionhealthcheck "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config"
)

var (
defaultSyncPeriod = time.Second * 30
// DefaultAddOptions are the default DefaultAddArgs for AddToManager.
DefaultAddOptions = extensionshealthcheckcontroller.DefaultAddArgs{
HealthCheckConfig: extensionhealthcheck.HealthCheckConfig{SyncPeriod: metav1.Duration{Duration: defaultSyncPeriod}},
}
)

// RegisterHealthChecks registers health checks for each extension resource
// HealthChecks are grouped by extension (e.g worker), extension.type (e.g aws) and Health Check Type (e.g SystemComponentsHealthy)
func RegisterHealthChecks(mgr manager.Manager, opts extensionshealthcheckcontroller.DefaultAddArgs) error {
return extensionshealthcheckcontroller.DefaultRegisterExtensionForHealthCheck(
certcontroller.Type,
extensionsv1alpha1.SchemeGroupVersion.WithKind(extensionsv1alpha1.ExtensionResource),
func() runtime.Object { return &extensionsv1alpha1.Extension{} },
mgr,
opts,
nil,
map[extensionshealthcheckcontroller.HealthCheck]string{
general.CheckManagedResource(certv1alpha1.CertManagementResourceNameSeed): string(gardencorev1alpha1.ShootControlPlaneHealthy),
general.CheckManagedResource(certv1alpha1.CertManagementResourceNameShoot): string(gardencorev1alpha1.ShootSystemComponentsHealthy),
})
}

// AddToManager adds a controller with the default Options.
func AddToManager(mgr manager.Manager) error {
return RegisterHealthChecks(mgr, DefaultAddOptions)
}
2 changes: 2 additions & 0 deletions controllers/extension-shoot-dns-service/cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ func (o *Options) run(ctx context.Context) {
}

o.serviceOptions.Completed().Apply(&config.ServiceConfig)
o.healthOptions.Completed().ApplyHealthCheckConfig(&config.HealthConfig)
o.controllerOptions.Completed().Apply(&config.ServiceConfig.ControllerOptions)
o.reconcileOptions.Completed().Apply(&config.ServiceConfig.IgnoreOperationAnnotation)
o.healthControllerOptions.Completed().Apply(&config.HealthConfig.ControllerOptions)

if err := o.controllerSwitches.Completed().AddToManager(mgr); err != nil {
controllercmd.LogErrAndExit(err, "Could not add controllers to manager")
Expand Down
23 changes: 16 additions & 7 deletions controllers/extension-shoot-dns-service/cmd/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ const ExtensionName = service.ExtensionServiceName

// Options holds configuration passed to the DNS Service controller.
type Options struct {
serviceOptions *dnsservicecmd.DNSServiceOptions
restOptions *controllercmd.RESTOptions
managerOptions *controllercmd.ManagerOptions
controllerOptions *controllercmd.ControllerOptions
controllerSwitches *controllercmd.SwitchOptions
reconcileOptions *controllercmd.ReconcilerOptions
optionAggregator controllercmd.OptionAggregator
serviceOptions *dnsservicecmd.DNSServiceOptions
healthOptions *dnsservicecmd.HealthOptions
restOptions *controllercmd.RESTOptions
managerOptions *controllercmd.ManagerOptions
controllerOptions *controllercmd.ControllerOptions
healthControllerOptions *controllercmd.ControllerOptions
controllerSwitches *controllercmd.SwitchOptions
reconcileOptions *controllercmd.ReconcilerOptions
optionAggregator controllercmd.OptionAggregator
}

// NewOptions creates a new Options instance.
func NewOptions() *Options {
options := &Options{
serviceOptions: &dnsservicecmd.DNSServiceOptions{},
healthOptions: &dnsservicecmd.HealthOptions{},
restOptions: &controllercmd.RESTOptions{},
managerOptions: &controllercmd.ManagerOptions{
// These are default values.
Expand All @@ -51,15 +54,21 @@ func NewOptions() *Options {
// This is a default value.
MaxConcurrentReconciles: 5,
},
healthControllerOptions: &controllercmd.ControllerOptions{
// This is a default value.
MaxConcurrentReconciles: 5,
},
controllerSwitches: dnsservicecmd.ControllerSwitches(),
reconcileOptions: &controllercmd.ReconcilerOptions{},
}

options.optionAggregator = controllercmd.NewOptionAggregator(
options.serviceOptions,
options.healthOptions,
options.restOptions,
options.managerOptions,
options.controllerOptions,
controllercmd.PrefixOption("healthcheck-", options.healthControllerOptions),
options.controllerSwitches,
options.reconcileOptions,
)
Expand Down
Loading

0 comments on commit 1c9b2b7

Please sign in to comment.