systemd

package
v0.0.0-...-566b0a1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Etcd = gen("etcd", map[string]string{
		"name":     "controller",
		"data-dir": config.DefaultEtcdDataDir,
	})
	KubeApiserver = func(cfg *config.Config) flow.Action {
		apiEndpoint := cfg.ControlPlain.LocalAPIEndpoint
		proxyClientCertFile := filepath.Join(config.DefaultCertificatesDir, "front-proxy-client.crt")
		proxyClientKeyFile := filepath.Join(config.DefaultCertificatesDir, "front-proxy-client.key")
		saIssuer := fmt.Sprintf("https://kubernetes.default.svc.%s", cfg.ControlPlain.DNSDomain)

		return gen("kube-apiserver", map[string]string{
			"advertise-address":                  apiEndpoint.AdvertiseAddress.String(),
			"allow-privileged":                   "true",
			"authorization-mode":                 "Node,RBAC",
			"client-ca-file":                     caCert,
			"enable-admission-plugins":           "NodeRestriction",
			"enable-bootstrap-token-auth":        "false",
			"etcd-servers":                       "http://127.0.0.1:2379",
			"proxy-client-cert-file":             proxyClientCertFile,
			"proxy-client-key-file":              proxyClientKeyFile,
			"requestheader-allowed-names":        "front-proxy-client",
			"requestheader-client-ca-file":       filepath.Join(config.DefaultCertificatesDir, "front-proxy-ca.crt"),
			"requestheader-extra-headers-prefix": "X-Remote-Extra-",
			"requestheader-group-headers":        "X-Remote-Group",
			"requestheader-username-headers":     "X-Remote-User",
			"secure-port":                        fmt.Sprintf("%d", apiEndpoint.BindPort),
			"service-account-issuer":             saIssuer,
			"service-account-key-file":           filepath.Join(config.DefaultCertificatesDir, "sa.pub"),
			"service-account-signing-key-file":   saKey,
			"service-cluster-ip-range":           cfg.ControlPlain.ServiceSubnet,
			"tls-cert-file":                      filepath.Join(config.DefaultCertificatesDir, "apiserver.crt"),
			"tls-private-key-file":               filepath.Join(config.DefaultCertificatesDir, "apiserver.key"),
		})
	}
	KubeControllerManager = func() flow.Action {
		kubeconfig := filepath.Join(config.DefaultKubernetesDir, "controller-manager.conf")
		return gen("kube-controller-manager", map[string]string{
			"authentication-kubeconfig":        kubeconfig,
			"authorization-kubeconfig":         kubeconfig,
			"client-ca-file":                   caCert,
			"cluster-name":                     "kubernetes",
			"cluster-signing-cert-file":        caCert,
			"cluster-signing-key-file":         caKey,
			"controllers":                      "*,bootstrapsigner,tokencleaner",
			"kubeconfig":                       kubeconfig,
			"root-ca-file":                     caCert,
			"service-account-private-key-file": saKey,
			"use-service-account-credentials":  "true",
			"bind-address":                     "127.0.0.1",
		})
	}()
	KubeScheduler = func() flow.Action {
		kubeconfig := filepath.Join(config.DefaultKubernetesDir, "scheduler.conf")
		return gen("kube-scheduler", map[string]string{
			"authentication-kubeconfig": kubeconfig,
			"authorization-kubeconfig":  kubeconfig,
			"kubeconfig":                kubeconfig,
			"bind-address":              "127.0.0.1",
		})
	}()
	Kubelet = gen("kubelet", map[string]string{
		"kubeconfig":    filepath.Join(config.DefaultKubernetesDir, "kubelet.conf"),
		"config":        filepath.Join(config.DefaultKubeletDir, "config.yaml"),
		"register-node": "true",
	})
	Coredns = gen("coredns", map[string]string{
		"config": filepath.Join(config.DefaultKubernetesDir, "Corefile"),
	})
	DaemonReload = func() flow.Action {
		action := func(ctx context.Context) (flow.StatusType, error) {
			out, err := exec.Command("systemctl", "daemon-reload").CombinedOutput()
			if err != nil {
				return flow.StatusFailed, fmt.Errorf("failed to reload systemd daemon reload: %s: %v", out, err)
			}

			return flow.StatusSuccess, nil
		}

		return flow.NewAction("daemon-reload", action)
	}()
	Enable = func(units ...string) flow.Action {
		action := func(ctx context.Context) (flow.StatusType, error) {
			for _, unit := range units {
				out, err := exec.Command("systemctl", "enable", unit).CombinedOutput()
				if err != nil {
					return flow.StatusFailed,
						fmt.Errorf("failed to enable systemd unit %q: %s: %v", unit, out, err)
				}
			}

			return flow.StatusSuccess, nil
		}

		return flow.NewAction("enable units", action)
	}
	Start = func(units ...string) flow.Action {
		action := func(ctx context.Context) (flow.StatusType, error) {
			for _, unit := range units {
				out, err := exec.Command("systemctl", "start", unit).CombinedOutput()
				if err != nil {
					return flow.StatusFailed,
						fmt.Errorf("failed to start systemd unit %q: %s: %v", unit, out, err)
				}
			}

			return flow.StatusSuccess, nil
		}

		return flow.NewAction("start units", action)
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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