-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add validating webhook * Add validating webhook
- Loading branch information
Showing
11 changed files
with
393 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cmd | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"gitlab.com/hooksie1/cmsnr/pkg/server" | ||
"os" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/manager/signals" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
) | ||
|
||
// validatingCmd represents the validating command | ||
var validatingCmd = &cobra.Command{ | ||
Use: "validating", | ||
Short: "Starts the cmsnr validating webhook", | ||
Run: validateServer, | ||
} | ||
|
||
func init() { | ||
startCmd.AddCommand(validatingCmd) | ||
} | ||
|
||
func validateServer(cmd *cobra.Command, args []string) { | ||
port := viper.GetInt("port") | ||
log.Debugf("validating webhook port: %d", port) | ||
log.Info("setting up webhook server") | ||
mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{}) | ||
if err != nil { | ||
log.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
validator := server.Validator{ | ||
Client: mgr.GetClient(), | ||
} | ||
|
||
mgrServer := mgr.GetWebhookServer() | ||
mgrServer.Port = port | ||
mgrServer.CertDir = "/var/lib/cmsnr" | ||
mgrServer.Register("/validate", &webhook.Admission{ | ||
Handler: &validator, | ||
}) | ||
|
||
log.Info("starting webhook server") | ||
if err := mgrServer.Start(signals.SetupSignalHandler()); err != nil { | ||
log.Errorf("unable to start webhook server: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.