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

Commit

Permalink
Merge pull request #472 from danielfoehrKn/extension-health-checks
Browse files Browse the repository at this point in the history
initial health check library implementation
  • Loading branch information
rfranzke authored Jan 10, 2020
2 parents d24e1c4 + ea54c2d commit 1979fd9
Show file tree
Hide file tree
Showing 393 changed files with 7,682 additions and 1,215 deletions.
4 changes: 3 additions & 1 deletion controllers/extension-shoot-cert-service/cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

serviceinstall "github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/service/install"
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/controller"
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/controller/healthcheck"
extensionscontroller "github.com/gardener/gardener-extensions/pkg/controller"
controllercmd "github.com/gardener/gardener-extensions/pkg/controller/cmd"
"github.com/gardener/gardener-extensions/pkg/util"
Expand Down Expand Up @@ -70,9 +71,10 @@ func (o *Options) run(ctx context.Context) {
}

ctrlConfig := o.certOptions.Completed()

ctrlConfig.ApplyHealthCheckConfig(&healthcheck.DefaultAddOptions.HealthCheckConfig)
ctrlConfig.Apply(&controller.DefaultAddOptions.ServiceConfig)
o.controllerOptions.Completed().Apply(&controller.DefaultAddOptions.ControllerOptions)
o.healthOptions.Completed().Apply(&healthcheck.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 is the config for the health check controller</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 @@ -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 @@ -15,6 +15,8 @@
package config

import (
healthcheckconfig "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config"

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

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

IssuerName string
ACME ACME
// HealthCheckConfig is the config for the health check controller
HealthCheckConfig *healthcheckconfig.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,8 @@
package v1alpha1

import (
healthcheckconfigv1alpha1 "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config/v1alpha1"

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

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

IssuerName string `json:"issuerName"`
ACME ACME `json:"acme"`
// HealthCheckConfig is the config for the health check controller
// +optional
HealthCheckConfig *healthcheckconfigv1alpha1.HealthCheckConfig `json:"healthCheckConfig,omitempty"`
}

// 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.

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package validation_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestTypeValidation(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
package validation_test

import (
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/config"
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/config/validation"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
gomegatypes "github.com/onsi/gomega/types"

"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/config"
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/config/validation"

"k8s.io/apimachinery/pkg/util/validation/field"
)

Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"net/url"

"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/service"
"github.com/gardener/gardener/pkg/utils"

"github.com/gardener/gardener/pkg/utils"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
package validation_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestTypeValidation(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
package validation_test

import (
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/service"
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/service/validation"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
gomegatypes "github.com/onsi/gomega/types"

"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/service"
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/service/validation"

"k8s.io/apimachinery/pkg/util/validation/field"
)

Expand Down
13 changes: 11 additions & 2 deletions controllers/extension-shoot-cert-service/pkg/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import (
"errors"
"io/ioutil"

"github.com/gardener/gardener-extensions/pkg/controller/cmd"

apisconfig "github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/config"
"github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/apis/config/v1alpha1"
"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"
"github.com/gardener/gardener-extensions/pkg/controller/cmd"
extensionshealthcheckcontroller "github.com/gardener/gardener-extensions/pkg/controller/healthcheck"
healthcheckconfig "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -102,5 +104,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 *healthcheckconfig.HealthCheckConfig) {
if c.config.HealthCheckConfig != nil {
*config = *c.config.HealthCheckConfig
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
package controller

import (
"github.com/gardener/gardener-extensions/pkg/controller/extension"

controllerconfig "github.com/gardener/gardener-extensions/controllers/extension-shoot-cert-service/pkg/controller/config"
"github.com/gardener/gardener-extensions/pkg/controller/extension"

"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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"

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"
"github.com/gardener/gardener-extensions/pkg/controller/healthcheck"
healthcheckconfig "github.com/gardener/gardener-extensions/pkg/controller/healthcheck/config"
"github.com/gardener/gardener-extensions/pkg/controller/healthcheck/general"

gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

var (
defaultSyncPeriod = time.Second * 30
// DefaultAddOptions are the default DefaultAddArgs for AddToManager.
DefaultAddOptions = healthcheck.DefaultAddArgs{
HealthCheckConfig: healthcheckconfig.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 healthcheck.DefaultAddArgs) error {
return healthcheck.DefaultRegistration(
certcontroller.Type,
extensionsv1alpha1.SchemeGroupVersion.WithKind(extensionsv1alpha1.ExtensionResource),
func() runtime.Object { return &extensionsv1alpha1.Extension{} },
mgr,
opts,
nil,
map[healthcheck.HealthCheck]string{
general.CheckManagedResource(certv1alpha1.CertManagementResourceNameSeed): string(gardencorev1beta1.ShootControlPlaneHealthy),
general.CheckManagedResource(certv1alpha1.CertManagementResourceNameShoot): string(gardencorev1beta1.ShootSystemComponentsHealthy),
})
}

// AddToManager adds a controller with the default Options.
func AddToManager(mgr manager.Manager) error {
return RegisterHealthChecks(mgr, DefaultAddOptions)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/gardener/gardener/pkg/utils/imagevector"
"github.com/gobuffalo/packr/v2"

"k8s.io/apimachinery/pkg/util/runtime"
)

Expand Down
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
Loading

0 comments on commit 1979fd9

Please sign in to comment.