k8s

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 60 Imported by: 0

Documentation

Overview

Copyright © 2021 Antoine Martin <antoine@openance.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2021 Antoine Martin <antoine@openance.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	RcConfPreventKubeletRunning = "rc_kubelet_need=\"non-existing-service\""
	RcConfIkniteNeedsNetworking = "rc_iknite_need=\"networking\""
)

Variables

View Source
var ApplicationSchemaGroupVersionKind = schema.GroupVersionKind{
	Group:   "argoproj.io",
	Version: "v1alpha1",
	Kind:    "Application",
}

Functions

func AreWorkloadsReady added in v0.1.19

func AreWorkloadsReady(
	config *Config,
	callback WorkloadStateCallbackFunc,
) wait.ConditionWithContextFunc

func CheckApiServerHealth added in v0.5.0

func CheckApiServerHealth(
	timeout time.Duration,
	checkData CheckData,
) (bool, string, error)

func CheckIkniteServerHealth added in v0.7.0

func CheckIkniteServerHealth(ctx context.Context, timeout time.Duration) (bool, string, error)

CheckIkniteServerHealth checks the /healthz endpoint of the iknite status server using the mTLS client configuration stored in constants.IkniteLocalConfPath (/root/.kube/iknite.conf). It returns true when the server responds with "ok".

func CheckKubeletHealth added in v0.5.0

func CheckKubeletHealth(timeout time.Duration) (bool, string, error)

func CheckKubeletRunning added in v0.4.0

func CheckKubeletRunning(retries, okResponses, waitTime int) error

func CheckPidFile added in v0.5.0

func CheckPidFile(service string, cmd *exec.Cmd) (int, error)

func CheckService added in v0.5.0

func CheckService(
	serviceName string,
	checkOpenRC, checkPidFile bool,
) (bool, string, error)

func CheckWorkloadResultPrinter added in v0.5.0

func CheckWorkloadResultPrinter(result *CheckResult, prefix, spinView string) string

func CheckWorkloads added in v0.5.0

func CheckWorkloads(ctx context.Context, data CheckData) (bool, string, error)

func CleanAll added in v0.4.0

func CleanAll(
	ikniteConfig *v1alpha1.IkniteClusterSpec,
	resetIpAddress, resetIpTables, failOnError, isDryRun bool,
) error

func DeleteAPIBackendData added in v0.6.3

func DeleteAPIBackendData(isDryRun bool, apiBackendName, apiBackendDatabaseDirectory string) error

DeleteAPIBackendData deletes the API backend data directory.

func DeleteCniNamespaces added in v0.5.0

func DeleteCniNamespaces(isDryRun bool) error

func DeleteNetworkInterfaces added in v0.5.0

func DeleteNetworkInterfaces(isDryRun bool) error

func EnableCGroupSubtreeControl added in v0.7.0

func EnableCGroupSubtreeControl() error

EnableCGroupSubtreeControl enables cgroup subtree control if it is not already enabled. This is required for kubelet to be able to manage cgroups properly. It does so by creating a new cgroup, moving all current processes to it, and then enabling subtree control for all controllers. We assume that we are running in a privileged container and that we have access to the cgroup filesystem. If this is not the case, this function will fail. We also assume that we are running with CGroups V2.

func EnsureConfigFileHasConfigurationLine added in v0.7.0

func EnsureConfigFileHasConfigurationLine(confFilePath, line string) error

EnsureConfigFileHasConfigurationLine ensures that the specified configuration line is present in the given configuration file. If the line is already present, it does nothing. If the line is not present, it adds it to the end of the file.

func EnsureNetworkInterfacesConfiguration added in v0.7.0

func EnsureNetworkInterfacesConfiguration() error

EnsureNetworkInterfacesConfiguration ensures that the /etc/network/interfaces file exists.

func FileTreeDifference added in v0.5.0

func FileTreeDifference(
	path string,
	expectedFiles []string,
) ([]string, []string, error)

FileTreeDifference computes the difference between an actual path and an expected file tree.

func FillResultNameMap added in v0.5.0

func FillResultNameMap(
	results []*CheckResult,
	resultNameMap map[string]*CheckResult,
) map[string]*CheckResult

FillResultNameMap fills a map with check results by name.

func GetIkniteConfigMap added in v0.1.20

func GetIkniteConfigMap(client kubernetes.Interface) (*coreV1.ConfigMap, error)

func HasConfigFileConfigurationLine added in v0.7.0

func HasConfigFileConfigurationLine(confFilePath, line string) (bool, error)

HasConfigFileConfigurationLine checks if the specified configuration line is present in the given configuration file. It returns true if the line is present, false otherwise.

func IsKubeletRunning added in v0.5.0

func IsKubeletRunning() (*os.Process, error)

IsKubeletRunning checks if the kubelet process is running.

func IsKubeletServiceRunnable added in v0.5.0

func IsKubeletServiceRunnable(confFilePath string) (bool, error)

IsKubeletServiceRunnable checks if the kubelet service is allowed to be started by the OpenRC init system. It does so by checking if the confFilePath file contains the line that prevents kubelet from being started.

func MakeIkniteServiceNeedNetworking added in v0.7.0

func MakeIkniteServiceNeedNetworking(confFilePath string) error

MakeIkniteServiceNeedNetworking ensures that the iknite OpenRC service has a dependency on the networking service, by

adding a line to the confFilePath file.

func PrepareKubernetesEnvironment added in v0.4.0

func PrepareKubernetesEnvironment(ikniteConfig *v1alpha1.IkniteClusterSpec) error

func PrettyPrintWorkloadState added in v0.5.0

func PrettyPrintWorkloadState(prefix string, r *v1alpha1.WorkloadState) string

func PreventKubeletServiceFromStarting added in v0.5.0

func PreventKubeletServiceFromStarting(confFilePath string) error

PreventKubeletServiceFromStarting ensures that the kubelet service is not started by the OpenRC init system. It does so by adding a line to the confFilePath file.

func RemoveKubeletFiles added in v0.5.0

func RemoveKubeletFiles(isDryRun bool) error

func RemovePidFiles added in v0.4.0

func RemovePidFiles()

func ResetIPAddress added in v0.4.0

func ResetIPAddress(ikniteConfig *v1alpha1.IkniteClusterSpec, isDryRun bool) error

func ResetIPTables added in v0.5.0

func ResetIPTables(isDryRun bool) error

func StartAndConfigureKubelet added in v0.4.0

func StartAndConfigureKubelet(kubeConfig *v1alpha1.IkniteClusterSpec) error

func StartKubelet added in v0.4.0

func StartKubelet() (*exec.Cmd, error)

func StatusViewerFor added in v0.1.19

func StatusViewerFor(kind schema.GroupKind) (polymorphichelpers.StatusViewer, error)

func StopAllContainers added in v0.5.0

func StopAllContainers(isDryRun bool) error

func UnmountPaths added in v0.5.0

func UnmountPaths(failOnError, isDryRun bool) error

func WriteIkniteConfigMap added in v0.1.20

func WriteIkniteConfigMap(
	client kubernetes.Interface,
	cm *coreV1.ConfigMap,
) (*coreV1.ConfigMap, error)

Types

type Application added in v0.1.19

type Application struct {
	Status            ApplicationStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
	metav1.TypeMeta   `                  json:",inline"`
	metav1.ObjectMeta `                  json:"metadata"         protobuf:"bytes,1,opt,name=metadata"`
}

type ApplicationStatus added in v0.1.19

type ApplicationStatus struct {
	Sync   SyncStatus   `json:"sync,omitempty"   protobuf:"bytes,2,opt,name=sync"`
	Health HealthStatus `json:"health,omitempty" protobuf:"bytes,3,opt,name=health"`
}

type ApplicationStatusViewer added in v0.1.19

type ApplicationStatusViewer struct{}

func (*ApplicationStatusViewer) Status added in v0.1.19

type Check added in v0.5.0

type Check struct {
	CheckFn          CheckFn
	CheckDataBuilder CheckDataBuilder
	CustomPrinter    CustomResultPrinter
	Name             string
	Description      string
	Message          string
	DependsOn        []string
	SubChecks        []*Check
}

func FileTreeCheck added in v0.5.0

func FileTreeCheck(name, description, path string, expectedFiles []string) *Check

FileTreeCheck checks if a file tree exists.

func KubernetesFileCheck added in v0.5.0

func KubernetesFileCheck(name, path string) *Check

KubernetesFileCheck checks if kubernetes configuration files exist.

func NewPhase added in v0.5.0

func NewPhase(name, description string, subChecks []*Check) *Check

func ServiceCheck added in v0.5.0

func ServiceCheck(name, serviceName string) *Check

ServiceCheck checks if a service is running.

func SystemFileCheck added in v0.5.0

func SystemFileCheck(name, description, path, expectedContent string) *Check

SystemFileCheck checks if a file exists and has specific content.

func (*Check) NewResult added in v0.5.0

func (c *Check) NewResult() *CheckResult

type CheckData added in v0.5.0

type CheckData any

func CreateCheckWorkloadData added in v0.5.0

func CreateCheckWorkloadData(apiAdvertiseAddress string) CheckData

type CheckDataBuilder added in v0.5.0

type CheckDataBuilder func() CheckData

type CheckExecutor added in v0.5.0

type CheckExecutor struct {
	Checks  []*Check
	Results []*CheckResult
	// contains filtered or unexported fields
}

func NewCheckExecutor added in v0.5.0

func NewCheckExecutor(checks []*Check) *CheckExecutor

NewCheckExecutor creates a new CheckExecutor.

func (*CheckExecutor) Run added in v0.5.0

func (e *CheckExecutor) Run(ctx context.Context) []*CheckResult

Run runs the checks.

type CheckFn added in v0.5.0

type CheckFn func(ctx context.Context, data CheckData) (bool, string, error)

type CheckModel added in v0.5.0

type CheckModel struct {
	// contains filtered or unexported fields
}

func NewCheckModel added in v0.5.0

func NewCheckModel(ctx context.Context, executor *CheckExecutor) CheckModel

func (CheckModel) Init added in v0.5.0

func (m CheckModel) Init() tea.Cmd

func (CheckModel) Update added in v0.5.0

func (m CheckModel) Update(
	msg tea.Msg,
) (tea.Model, tea.Cmd)

func (CheckModel) View added in v0.5.0

func (m CheckModel) View() string

type CheckResult added in v0.5.0

type CheckResult struct {
	Error         error
	CheckData     CheckData
	Check         *Check
	Done          chan struct{}
	Message       string
	SubResults    []*CheckResult
	ParentResults []*CheckResult
	Status        CheckStatus
}

func PrepareChecks added in v0.5.0

func PrepareChecks(checks []*Check) []*CheckResult

PrepareChecks prepares the checks for running.

func RunChecks added in v0.5.0

func RunChecks(ctx context.Context, results []*CheckResult) []*CheckResult

RunChecks runs the checks.

func (*CheckResult) CheckFn added in v0.5.0

func (c *CheckResult) CheckFn(ctx context.Context) *CheckResult

func (*CheckResult) Failed added in v0.5.0

func (r *CheckResult) Failed() bool

func (*CheckResult) FillDependencies added in v0.5.0

func (r *CheckResult) FillDependencies(resultNameMap map[string]*CheckResult)

func (*CheckResult) Format added in v0.5.0

func (result *CheckResult) Format(prefix, spinView string) string

func (*CheckResult) FormatResult added in v0.5.0

func (result *CheckResult) FormatResult(prefix, spinView string) string

func (*CheckResult) Name added in v0.5.0

func (r *CheckResult) Name() string

func (*CheckResult) Run added in v0.5.0

func (c *CheckResult) Run(ctx context.Context)

func (*CheckResult) StatusString added in v0.5.0

func (result *CheckResult) StatusString(spinView string) string

func (*CheckResult) Success added in v0.5.0

func (r *CheckResult) Success() bool

type CheckStatus added in v0.5.0

type CheckStatus int
const (
	StatusPending CheckStatus = iota
	StatusRunning
	StatusSkipped
	StatusSuccess
	StatusFailed
)

type CheckWorkloadData added in v0.5.0

type CheckWorkloadData interface {
	IsOk() bool
	WorkloadCount() int
	ReadyWorkloads() []*v1alpha1.WorkloadState
	NotReadyWorkloads() []*v1alpha1.WorkloadState
	Iteration() int
	Duration() time.Duration
	SetOk(bool)
	SetWorkloadCount(int)
	SetReadyWorkloads([]*v1alpha1.WorkloadState)
	SetNotReadyWorkloads([]*v1alpha1.WorkloadState)
	SetIteration(int)
	Start()
	ApiAdvertiseAddress() string
	ManifestDir() string
}

type Config

type Config api.Config

func LoadFromDefault

func LoadFromDefault() (*Config, error)

LoadFromDefault loads the configuration from the default admin.conf file, usually located at /etc/kubernetes/admin.conf.

func LoadFromFile added in v0.1.15

func LoadFromFile(filename string) (*Config, error)

LoadFromFile loads the configuration from the file specified by filename.

func (*Config) CheckClusterRunning

func (config *Config) CheckClusterRunning(retries, okResponses, waitTime int) error

CheckClusterRunning checks that the cluster is running by requesting the API server /readyz endpoint. It checks retries times and waits for waitTime milliseconds between each check. It needs at least okResponses good responses from the server.

func (*Config) Client

func (config *Config) Client() (*kubernetes.Clientset, error)

Client returns a clientset for config.

func (*Config) DoKustomization added in v0.5.0

func (config *Config) DoKustomization(
	ip net.IP,
	kustomization string,
	force bool,
	waitTimeout int,
) error

DoKustomization applies Kubernetes kustomizations to configure the cluster. It takes an outbound IP address, a kustomization path or content, a force flag, and a wait timeout in seconds.

The function checks if configuration has already been applied by reading the 'configured' field in the iknite ConfigMap. If already configured and force is false, it logs a warning and skips configuration. Otherwise, it applies the provided kustomization using provision.ApplyBaseKustomizations and marks the cluster as configured by updating the ConfigMap.

If waitTimeout is greater than 0, the function waits for all workloads to be ready for the specified duration before returning.

Returns an error if the client cannot be created, the ConfigMap cannot be read or written, kustomizations fail to apply, or workloads don't become ready within the timeout period.

func (*Config) HTTPClient added in v0.7.0

func (config *Config) HTTPClient() (*http.Client, error)

HTTPClient returns an HTTP client for config.

func (*Config) IsConfigServerAddress

func (config *Config) IsConfigServerAddress(address string) bool

IsConfigServerAddress checks that config points to the server at ip IP address.

func (*Config) NewRESTClient added in v0.7.0

func (config *Config) NewRESTClient() (rest.Interface, error)

Return a REST client for config. To make simple HTTP requests to the API server.

func (*Config) RESTClient added in v0.1.19

func (config *Config) RESTClient() *RESTClientGetter

func (*Config) RenameConfig

func (c *Config) RenameConfig(newName string) *Config

RenameConfig changes the name of the cluster and the context from the default (kubernetes) to newName in c.

func (*Config) RestartProxy

func (config *Config) RestartProxy() error

RestartProxy restarts kube-proxy after config has been updated. This needs to be done after an IP address change. The restart method is taken from kubectl: https://github.com/kubernetes/kubectl/blob/ 652881798563c00c1895ded6ced819030bfaa4d7/pkg/polymorphichelpers/objectrestarter.go#L81.

func (*Config) WaitForWorkloads added in v0.1.19

func (config *Config) WaitForWorkloads(
	ctx context.Context, timeout time.Duration, callback WorkloadStateCallbackFunc,
) error

func (*Config) WriteToFile

func (config *Config) WriteToFile(filename string) error

WriteToFile writes the config configuration to the file pointed by filename. It returns the appropriate error in case of failure.

type CustomResultPrinter added in v0.5.0

type CustomResultPrinter func(result *CheckResult, prefix string, spinView string) string

type HealthStatus added in v0.1.19

type HealthStatus struct {
	// Status holds the status code of the application or resource
	Status string `json:"status,omitempty" protobuf:"bytes,1,opt,name=status"`
	// Message is a human-readable informational message describing the health status
	Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"`
}

type RESTClientGetter added in v0.1.19

type RESTClientGetter struct {
	// contains filtered or unexported fields
}

func (*RESTClientGetter) AllWorkloadStates added in v0.1.19

func (client *RESTClientGetter) AllWorkloadStates() ([]*v1alpha1.WorkloadState, error)

func (*RESTClientGetter) ApplyResourceInfosServerSide added in v0.7.0

func (r *RESTClientGetter) ApplyResourceInfosServerSide(infos []*resource.Info) error

func (*RESTClientGetter) HasApplications added in v0.1.19

func (client *RESTClientGetter) HasApplications() (bool, error)

func (*RESTClientGetter) ResourceInfosFromResMap added in v0.7.0

func (r *RESTClientGetter) ResourceInfosFromResMap(resources resmap.ResMap) ([]*resource.Info, error)

func (*RESTClientGetter) ToDiscoveryClient added in v0.1.19

func (r *RESTClientGetter) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*RESTClientGetter) ToRESTConfig added in v0.1.19

func (r *RESTClientGetter) ToRESTConfig() (*rest.Config, error)

func (*RESTClientGetter) ToRESTMapper added in v0.1.19

func (r *RESTClientGetter) ToRESTMapper() (meta.RESTMapper, error)

func (*RESTClientGetter) ToRawKubeConfigLoader added in v0.1.19

func (r *RESTClientGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig

type SyncStatus added in v0.1.19

type SyncStatus struct {
	Status string `json:"status" protobuf:"bytes,1,opt,name=status,casttype=SyncStatusCode"`
}

type WorkloadStateCallbackFunc added in v0.1.19

type WorkloadStateCallbackFunc func(state bool, total int, ready []*v1alpha1.WorkloadState,
	unready []*v1alpha1.WorkloadState, iteration int) bool

Directories

Path Synopsis
phases

Jump to

Keyboard shortcuts

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