Skip to content
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
19 changes: 11 additions & 8 deletions cmd/standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ func main() {
var secureMetrics bool
var enableHTTP2 bool

awConfig := config.NewConfig(namespaceOrDie())
awConfig.StandaloneMode = true
awConfig.ManageJobsWithoutQueueName = false
cfg := &config.OperatorConfig{
AppWrapper: config.NewAppWrapperConfig(),
CertManagement: config.NewCertManagementConfig(namespaceOrDie()),
}
cfg.AppWrapper.StandaloneMode = true
cfg.AppWrapper.ManageJobsWithoutQueueName = false

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -81,9 +84,9 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
setupLog.Info("Build info", "version", BuildVersion, "date", BuildDate)
setupLog.Info("Configuration", "config", awConfig)
setupLog.Info("Configuration", "config", cfg)

if err := config.ValidateConfig(awConfig); err != nil {
if err := config.ValidateAppWrapperConfig(cfg.AppWrapper); err != nil {
setupLog.Error(err, "invalid appwrapper config")
os.Exit(1)
}
Expand Down Expand Up @@ -142,16 +145,16 @@ func main() {
if os.Getenv("ENABLE_WEBHOOKS") == "false" {
close(certsReady)
} else {
if err := controller.SetupCertManagement(mgr, &awConfig.CertManagement, certsReady); err != nil {
if err := controller.SetupCertManagement(mgr, cfg.CertManagement, certsReady); err != nil {
setupLog.Error(err, "Unable to set up cert rotation")
os.Exit(1)
}
}

// Ascynchronous because controllers need to wait for certificate to be ready for webhooks to work
go controller.SetupControllers(ctx, mgr, awConfig, certsReady, setupLog)
go controller.SetupControllers(ctx, mgr, cfg.AppWrapper, certsReady, setupLog)

if err := controller.SetupIndexers(ctx, mgr, awConfig); err != nil {
if err := controller.SetupIndexers(ctx, mgr, cfg.AppWrapper); err != nil {
setupLog.Error(err, "unable to setup indexers")
os.Exit(1)
}
Expand Down
18 changes: 11 additions & 7 deletions cmd/unified/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ func main() {
var secureMetrics bool
var enableHTTP2 bool

awConfig := config.NewConfig(namespaceOrDie())
cfg := &config.OperatorConfig{
AppWrapper: config.NewAppWrapperConfig(),
CertManagement: config.NewCertManagementConfig(namespaceOrDie()),
}

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -73,7 +76,8 @@ func main() {
"If set the metrics endpoint is served securely")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.BoolVar(&awConfig.ManageJobsWithoutQueueName, "manage-no-queue", true, "Manage AppWrappers without queue names")
flag.BoolVar(&cfg.AppWrapper.ManageJobsWithoutQueueName,
"manage-no-queue", true, "Manage AppWrappers without queue names")
opts := zap.Options{
Development: true,
}
Expand All @@ -82,9 +86,9 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
setupLog.Info("Build info", "version", BuildVersion, "date", BuildDate)
setupLog.Info("Configuration", "config", awConfig)
setupLog.Info("Configuration", "config", cfg)

if err := config.ValidateConfig(awConfig); err != nil {
if err := config.ValidateAppWrapperConfig(cfg.AppWrapper); err != nil {
setupLog.Error(err, "invalid appwrapper config")
os.Exit(1)
}
Expand Down Expand Up @@ -143,16 +147,16 @@ func main() {
if os.Getenv("ENABLE_WEBHOOKS") == "false" {
close(certsReady)
} else {
if err := controller.SetupCertManagement(mgr, &awConfig.CertManagement, certsReady); err != nil {
if err := controller.SetupCertManagement(mgr, cfg.CertManagement, certsReady); err != nil {
setupLog.Error(err, "Unable to set up cert rotation")
os.Exit(1)
}
}

// Ascynchronous because controllers need to wait for certificate to be ready for webhooks to work
go controller.SetupControllers(ctx, mgr, awConfig, certsReady, setupLog)
go controller.SetupControllers(ctx, mgr, cfg.AppWrapper, certsReady, setupLog)

if err := controller.SetupIndexers(ctx, mgr, awConfig); err != nil {
if err := controller.SetupIndexers(ctx, mgr, cfg.AppWrapper); err != nil {
setupLog.Error(err, "unable to setup indexers")
os.Exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("AppWrapper Controller", func() {
Name: aw.Name,
Namespace: aw.Namespace,
}
awConfig := config.NewConfig("")
awConfig := config.NewAppWrapperConfig()
awConfig.FaultTolerance.FailureGracePeriod = 0 * time.Second
awConfig.FaultTolerance.ResetPause = 0 * time.Second
awConfig.FaultTolerance.RetryLimit = 0
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var _ = BeforeSuite(func() {
})
Expect(err).NotTo(HaveOccurred())

err = (&AppWrapperWebhook{Config: config.NewConfig("")}).SetupWebhookWithManager(mgr)
err = (&AppWrapperWebhook{Config: config.NewAppWrapperConfig()}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:webhook
Expand Down
44 changes: 26 additions & 18 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ import (
"time"
)

type OperatorConfig struct {
AppWrapper *AppWrapperConfig `json:"appWrapper,omitempty"`
CertManagement *CertManagementConfig `json:"certManagement,omitempty"`
}

type AppWrapperConfig struct {
ManageJobsWithoutQueueName bool `json:"manageJobsWithoutQueueName,omitempty"`
StandaloneMode bool `json:"standaloneMode,omitempty"`
FaultTolerance FaultToleranceConfig `json:"faultTolerance,omitempty"`
CertManagement CertManagementConfig `json:"certManagement,omitempty"`
ManageJobsWithoutQueueName bool `json:"manageJobsWithoutQueueName,omitempty"`
StandaloneMode bool `json:"standaloneMode,omitempty"`
FaultTolerance *FaultToleranceConfig `json:"faultTolerance,omitempty"`
}

type FaultToleranceConfig struct {
Expand All @@ -48,33 +52,23 @@ type CertManagementConfig struct {
WebhookSecretName string `json:"webhookSecretName,omitempty"`
}

// NewConfig constructs an AppWrapperConfig and fills in default values
func NewConfig(namespace string) *AppWrapperConfig {
// NewAppWrapperConfig constructs an AppWrapperConfig and fills in default values
func NewAppWrapperConfig() *AppWrapperConfig {
return &AppWrapperConfig{
ManageJobsWithoutQueueName: true,
StandaloneMode: false,
FaultTolerance: FaultToleranceConfig{
FaultTolerance: &FaultToleranceConfig{
WarmupGracePeriod: 5 * time.Minute,
FailureGracePeriod: 1 * time.Minute,
ResetPause: 90 * time.Second,
RetryLimit: 3,
DeletionGracePeriod: 10 * time.Minute,
GracePeriodCeiling: 24 * time.Hour,
},
CertManagement: CertManagementConfig{
Namespace: namespace,
CertificateDir: "/tmp/k8s-webhook-server/serving-certs",
CertificateName: "appwrapper-ca",
CertificateOrg: "appwrapper",
MutatingWebhookConfigName: "appwrapper-mutating-webhook-configuration",
ValidatingWebhookConfigName: "appwrapper-validating-webhook-configuration",
WebhookServiceName: "appwrapper-webhook-service",
WebhookSecretName: "appwrapper-webhook-server-cert",
},
}
}

func ValidateConfig(config *AppWrapperConfig) error {
func ValidateAppWrapperConfig(config *AppWrapperConfig) error {
if config.FaultTolerance.DeletionGracePeriod > config.FaultTolerance.GracePeriodCeiling {
return fmt.Errorf("DelectionGracePeriod %v exceeds GracePeriodCeiling %v",
config.FaultTolerance.DeletionGracePeriod, config.FaultTolerance.GracePeriodCeiling)
Expand All @@ -94,3 +88,17 @@ func ValidateConfig(config *AppWrapperConfig) error {

return nil
}

// NewCertManagermentConfig constructs a CertManagementConfig and fills in default values
func NewCertManagementConfig(namespace string) *CertManagementConfig {
return &CertManagementConfig{
Namespace: namespace,
CertificateDir: "/tmp/k8s-webhook-server/serving-certs",
CertificateName: "appwrapper-ca",
CertificateOrg: "appwrapper",
MutatingWebhookConfigName: "appwrapper-mutating-webhook-configuration",
ValidatingWebhookConfigName: "appwrapper-validating-webhook-configuration",
WebhookServiceName: "appwrapper-webhook-service",
WebhookSecretName: "appwrapper-webhook-server-cert",
}
}