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

feat: Add a flag to support removing GRPC probe at runtime #1020

Merged
merged 1 commit into from
Jan 20, 2020
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
5 changes: 5 additions & 0 deletions cmd/katib-controller/v1alpha3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func main() {
var certLocalFS bool
var injectSecurityContext bool
var serviceName string
var enableGRPCProbeInSuggestion bool

flag.StringVar(&experimentSuggestionName, "experiment-suggestion-name",
"default", "The implementation of suggestion interface in experiment controller (default|fake)")
Expand All @@ -51,13 +52,15 @@ func main() {
flag.BoolVar(&certLocalFS, "cert-localfs", false, "Store the webhook cert in local file system")
flag.BoolVar(&injectSecurityContext, "webhook-inject-securitycontext", false, "Inject the securityContext of container[0] in the sidecar")
flag.StringVar(&serviceName, "webhook-service-name", "katib-controller", "The service name which will be used in webhook")
flag.BoolVar(&enableGRPCProbeInSuggestion, "enable-grpc-probe-in-suggestion", true, "enable grpc probe in suggestions")

flag.Parse()

// Set the config in viper.
viper.Set(consts.ConfigExperimentSuggestionName, experimentSuggestionName)
viper.Set(consts.ConfigCertLocalFS, certLocalFS)
viper.Set(consts.ConfigInjectSecurityContext, injectSecurityContext)
viper.Set(consts.ConfigEnableGRPCProbeInSuggestion, enableGRPCProbeInSuggestion)

log.Info("Config:",
consts.ConfigExperimentSuggestionName,
Expand All @@ -70,6 +73,8 @@ func main() {
metricsAddr,
consts.ConfigInjectSecurityContext,
viper.GetBool(consts.ConfigInjectSecurityContext),
consts.ConfigEnableGRPCProbeInSuggestion,
viper.GetBool(consts.ConfigEnableGRPCProbeInSuggestion),
)

// Get a config to talk to the apiserver
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller.v1alpha3/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const (
// if we should inject the security context into the metrics collector
// sidecar.
ConfigInjectSecurityContext = "inject-security-context"
// ConfigEnableGRPCProbeInSuggestion is the config name which indicates
// if we should set GRPC probe in suggestion deployments.
ConfigEnableGRPCProbeInSuggestion = "enable-grpc-probe-in-suggestion"

// LabelExperimentName is the label of experiment name.
LabelExperimentName = "experiment"
Expand Down
49 changes: 26 additions & 23 deletions pkg/controller.v1alpha3/suggestion/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package composer
import (
"fmt"

"github.com/spf13/viper"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -175,33 +176,35 @@ func (g *General) desiredContainer(s *suggestionsv1alpha3.Suggestion) (*corev1.C
},
}

c.ReadinessProbe = &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{
defaultGRPCHealthCheckProbe,
fmt.Sprintf("-addr=:%d", consts.DefaultSuggestionPort),
fmt.Sprintf("-service=%s", consts.DefaultGRPCService),
if viper.GetBool(consts.ConfigEnableGRPCProbeInSuggestion) {
c.ReadinessProbe = &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{
defaultGRPCHealthCheckProbe,
fmt.Sprintf("-addr=:%d", consts.DefaultSuggestionPort),
fmt.Sprintf("-service=%s", consts.DefaultGRPCService),
},
},
},
},
InitialDelaySeconds: defaultInitialDelaySeconds,
PeriodSeconds: defaultPeriodForReady,
}
c.LivenessProbe = &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{
defaultGRPCHealthCheckProbe,
fmt.Sprintf("-addr=:%d", consts.DefaultSuggestionPort),
fmt.Sprintf("-service=%s", consts.DefaultGRPCService),
InitialDelaySeconds: defaultInitialDelaySeconds,
PeriodSeconds: defaultPeriodForReady,
}
c.LivenessProbe = &corev1.Probe{
Handler: corev1.Handler{
Exec: &corev1.ExecAction{
Command: []string{
defaultGRPCHealthCheckProbe,
fmt.Sprintf("-addr=:%d", consts.DefaultSuggestionPort),
fmt.Sprintf("-service=%s", consts.DefaultGRPCService),
},
},
},
},
// Ref https://srcco.de/posts/kubernetes-liveness-probes-are-dangerous.html
InitialDelaySeconds: defaultInitialDelaySeconds,
PeriodSeconds: defaultPeriodForLive,
FailureThreshold: defaultFailureThreshold,
// Ref https://srcco.de/posts/kubernetes-liveness-probes-are-dangerous.html
InitialDelaySeconds: defaultInitialDelaySeconds,
PeriodSeconds: defaultPeriodForLive,
FailureThreshold: defaultFailureThreshold,
}
}
return c, nil
}