Skip to content

Commit

Permalink
feat(config): Add a new config for webhook (#980)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege authored and k8s-ci-robot committed Dec 17, 2019
1 parent 27fbd98 commit c426a76
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
10 changes: 9 additions & 1 deletion cmd/katib-controller/v1alpha3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,26 @@ func main() {
var experimentSuggestionName string
var metricsAddr string
var webhookPort int
var certLocalFS bool

flag.StringVar(&experimentSuggestionName, "experiment-suggestion-name",
"default", "The implementation of suggestion interface in experiment controller (default|fake)")
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.IntVar(&webhookPort, "webhook-port", 8443, "The port number to be used for admission webhook server.")
flag.BoolVar(&certLocalFS, "cert-localfs", false, "Store the webhook cert in local file system")

flag.Parse()

// Set the config in viper.
viper.Set(consts.ConfigExperimentSuggestionName, experimentSuggestionName)
viper.Set(consts.ConfigCertLocalFS, certLocalFS)

log.Info("Config:",
consts.ConfigExperimentSuggestionName,
viper.GetString(consts.ConfigExperimentSuggestionName))
viper.GetString(consts.ConfigExperimentSuggestionName),
consts.ConfigCertLocalFS,
viper.GetBool(consts.ConfigCertLocalFS),
)

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
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 @@ -6,6 +6,9 @@ const (
// ConfigExperimentSuggestionName is the config name of the
// suggestion client implementation in experiment controller.
ConfigExperimentSuggestionName = "experiment-suggestion-name"
// ConfigCertLocalFS is the config name which indicates if we
// should store the cert in file system.
ConfigCertLocalFS = "cert-local-filesystem"

// LabelExperimentName is the label of experiment name.
LabelExperimentName = "experiment"
Expand Down
20 changes: 14 additions & 6 deletions pkg/webhook/v1alpha3/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package webhook

import (
"github.com/spf13/viper"
admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -36,13 +37,9 @@ const (
)

func AddToManager(m manager.Manager, port int32) error {
server, err := webhook.NewServer("katib-admission-server", m, webhook.ServerOptions{
so := webhook.ServerOptions{
CertDir: "/tmp/cert",
BootstrapOptions: &webhook.BootstrapOptions{
Secret: &types.NamespacedName{
Namespace: consts.DefaultKatibNamespace,
Name: katibControllerName,
},
Service: &webhook.Service{
Namespace: consts.DefaultKatibNamespace,
Name: katibControllerName,
Expand All @@ -54,7 +51,18 @@ func AddToManager(m manager.Manager, port int32) error {
MutatingWebhookConfigName: "katib-mutating-webhook-config",
},
Port: port,
})
}

// Decide if we should use local file system.
// If not, we set a secret in BootstrapOptions.
usingFS := viper.GetBool(consts.ConfigCertLocalFS)
if !usingFS {
so.BootstrapOptions.Secret = &types.NamespacedName{
Namespace: consts.DefaultKatibNamespace,
Name: katibControllerName,
}
}
server, err := webhook.NewServer("katib-admission-server", m, so)
if err != nil {
return err
}
Expand Down

0 comments on commit c426a76

Please sign in to comment.