penguin/monok8s

k8s image for Mono Gateway Dev Kit

clitools/pkg/node/kubectl.go

raw ยท 652 bytes

package node

import (
	"context"
	"time"

	"k8s.io/klog/v2"

	system "example.com/monok8s/pkg/system"
)

const (
	crdsPath = "/usr/lib/monok8s/crds/"
)

func ApplyCRDs(ctx context.Context, nctx *NodeContext) error {
	if nctx.Config.Spec.ClusterRole != "control-plane" {
		return nil
	}

	_, err := nctx.SystemRunner.RunWithOptions(
		ctx,
		"kubectl",
		[]string{"--kubeconfig", adminKubeconfigPath, "apply", "-f", crdsPath},
		system.RunOptions{
			Timeout:      10 * time.Minute,
			OnStdoutLine: func(line string) { klog.Infof("[kubectl] %s", line) },
			OnStderrLine: func(line string) { klog.Infof("[kubectl] %s", line) },
		},
	)

	return err
}