cmd

package
v0.0.0-...-7066132 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InitCmd = &cobra.Command{
	Use:   "init",
	Short: "Init core to k8s",
	Long:  `Init core to k8s`,
	Run: func(cmd *cobra.Command, args []string) {
		mod, _ := cmd.Flags().GetString("mod")
		log.Printf("successed to get mod: %v", mod)

		port, _ := cmd.Flags().GetString("port")
		name, _ := cmd.Flags().GetString("name")
		namespace, _ := cmd.Flags().GetString("namespace")

		intPort, err := strconv.Atoi(port)
		int32Value := int32(intPort)
		if err != nil {
			panic(err)
		}

		client, err := k8s.Client()
		if err != nil {
			panic(err.Error())
		}

		var (
			webhookHost string
			vc          v1.WebhookClientConfig
			mc          v1.WebhookClientConfig
			vcPath      = "/v1/validate"
			mcPath      = "/v1/inject"
		)
		if mod == "debug" {
			webhookHost = "host.docker.internal"
			vcWebhookURL := fmt.Sprintf("https://%s:%s%s", webhookHost, port, vcPath)
			mcWebhookURL := fmt.Sprintf("https://%s:%s%s", webhookHost, port, mcPath)
			vc.URL = &vcWebhookURL
			mc.URL = &mcWebhookURL
		}
		if mod == "release" {
			webhookHost = fmt.Sprintf("%s.%s.svc", name, namespace)
			vc.Service = &v1.ServiceReference{
				Namespace: namespace,
				Name:      name,
				Path:      &vcPath,
				Port:      &int32Value,
			}
			mc.Service = &v1.ServiceReference{
				Namespace: namespace,
				Name:      name,
				Path:      &mcPath,
				Port:      &int32Value,
			}
		}
		generateSelfSignedCert(webhookHost)
		pemData, err := os.ReadFile(certFile)
		if err != nil {
			panic(err)
		}
		vc.CABundle = pemData
		mc.CABundle = pemData
		createValidatingWebhookConfig(name, client, vc)
		createMutatingWebhookConfig(name, client, mc)
	},
}

Functions

func Execute

func Execute() error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL