util

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SkipReconcileAnnotation defines the annotation which marks the object should not be reconciled
	SkipReconcileAnnotation = "operator.openyurt.io/skip-reconcile"

	// ControlPlaneLabel defines the label for control-plane node
	ControlPlaneLabel = "node-role.kubernetes.io/master"
)

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, yamlContent string) error

Apply applies the manifests into cluster.

func ApplyTemplateWithRender

func ApplyTemplateWithRender(ctx context.Context, template *corev1.ConfigMap, dataKey string, values map[string]string) error

ApplyTemplateWithRender renders and applies the manifests into cluster.

func CopyFile

func CopyFile(sourceFile string, destinationFile string) error

CopyFile copies sourceFile to destinationFile

func Delete

func Delete(ctx context.Context, yamlContent string) error

Delete deletes the manifests from cluster.

func DeleteTemplateWithRender

func DeleteTemplateWithRender(ctx context.Context, template *corev1.ConfigMap, dataKey string, values map[string]string) error

DeleteTemplateWithRender renders and deletes the manifests from cluster.

func DisableNodeLifeCycleController

func DisableNodeLifeCycleController(filePath string) error

DisableNodeLifeCycleController disables nodelifecycle controller for kube-controller-manager

func EnableNodeLifeCycleController

func EnableNodeLifeCycleController(filePath string) error

EnableNodeLifeCycleController enables nodelifecycle controller for kube-controller-manager

func FileExists

func FileExists(filename string) (bool, error)

FileExists determines whether the file exists

func FileSameContent

func FileSameContent(sourceFile string, destinationFile string) (bool, error)

FileSameContent determines whether the source file and destination file is same

func Get

func Get(ctx context.Context, yamlContent string) (*unstructured.Unstructured, error)

Get gets object based on the yaml manifests from cluster.

func GetCmdLineByPid

func GetCmdLineByPid(pid int) (string, error)

GetCmdLineByPid returns the service CMDLine by PID

func GetContentFormString

func GetContentFormString(content string, regularExpression string) []string

GetContentFormString returns all strings that match the regular expression regularExpression

func GetControlPlaneSize

func GetControlPlaneSize(ctx context.Context, cli client.Client) (int, error)

GetControlPlaneSize returns the size of control-plane

func GetNodeCondition

func GetNodeCondition(status *corev1.NodeStatus, conditionType corev1.NodeConditionType) (int, *corev1.NodeCondition)

GetNodeCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.

func GetServiceCmdLine

func GetServiceCmdLine(name string) (string, error)

GetServiceCmdLine returns the cmd line of given service

func GetSingleContentPreferLastMatchFromFile

func GetSingleContentPreferLastMatchFromFile(filename string, regularExpression string) (string, error)

GetSingleContentPreferLastMatchFromFile determines whether there is a unique string that matches the regular expression regularExpression and returns it. If multiple values exist, return the last one.

func GetSingleContentPreferLastMatchFromString

func GetSingleContentPreferLastMatchFromString(content string, regularExpression string) (string, error)

GetSingleContentPreferLastMatchFromString determines whether there is a unique string that matches the regular expression regularExpression and returns it. If multiple values exist, return the last one.

func GetYurtComponentImageByType

func GetYurtComponentImageByType(yurtCluster *operatorv1alpha1.YurtCluster, imageType YurtImageType) string

GetYurtComponentImageByType returns the full image name of OpenYurt component by ImageType

func IsControlPlaneNode

func IsControlPlaneNode(node *corev1.Node) bool

IsControlPlaneNode returns true when the node is control-plane node

func IsNodeReady

func IsNodeReady(node *corev1.Node) bool

IsNodeReady returns true if the node is ready

func MarshalToYaml

func MarshalToYaml(obj runtime.Object, gv schema.GroupVersion) ([]byte, error)

MarshalToYaml marshals an object into yaml.

func MarshalToYamlForCodecs

func MarshalToYamlForCodecs(obj runtime.Object, gv schema.GroupVersion, codecs serializer.CodecFactory) ([]byte, error)

MarshalToYamlForCodecs marshals an object into yaml using the specified codec

func ObjectToYaml

func ObjectToYaml(obj runtime.Object) (string, error)

ObjectToYaml serializes the object to yaml format

func RenderTemplate

func RenderTemplate(tmpl string, context map[string]string) (string, error)

RenderTemplate fills out the manifest template with the context.

func RestartService

func RestartService(service string) error

RestartService tries to restart a service. Currently, only systemd service is supported.

func RunCommand

func RunCommand(cmd string) ([]byte, error)

RunCommand runs a command by sh shell.

func RunCommandWithCombinedOutput

func RunCommandWithCombinedOutput(cmd string) ([]byte, error)

RunCommandWithCombinedOutput runs a command by sh shell with combined output.

func ShouldSkip

func ShouldSkip(ctx context.Context, yamlContent string) bool

ShouldSkip returns true if the object contains SkipReconcileAnnotation annotation with true value.

func YamlToObject

func YamlToObject(yamlContent []byte) (client.Object, error)

YamlToObject deserializes object in yaml format to a client.Object

Types

type YurtImageType

type YurtImageType int

YurtImageType defines the image type for yurt components

const (
	// YurtHubImageForCloudNode represents the yurt hub image for cloud node
	YurtHubImageForCloudNode YurtImageType = iota
	// YurtHubImageForEdgeNode represents the yurt hub image for edge node
	YurtHubImageForEdgeNode
	// YurtTunnelServerImage represents the yurt tunnel server image
	YurtTunnelServerImage
	// YurtTunnelAgentImage represents the yurt tunnel agent image
	YurtTunnelAgentImage
)

Jump to

Keyboard shortcuts

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