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(config): Add a new config for webhook #980

Merged
merged 1 commit into from
Dec 17, 2019
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
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