util

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CertificateBlockType = "CERTIFICATE"

	// ECPrivateKeyBlockType is a possible value for pem.Block.Type.
	ECPrivateKeyBlockType = "EC PRIVATE KEY"

	// RSAPrivateKeyBlockType is a possible value for pem.Block.Type.
	RSAPrivateKeyBlockType = "RSA PRIVATE KEY"

	// PrivateKeyBlockType is a possible value for pem.Block.Type.
	PrivateKeyBlockType = "PRIVATE KEY"

	// PublicKeyBlockType is a possible value for pem.Block.Type.
	PublicKeyBlockType = "PUBLIC KEY"
)
View Source
const (
	EdgeNodeLabelKey   = "superedge.io/node-edge"
	CloudNodeLabelKey  = "superedge.io/node-cloud"
	EdgeMasterLabelKey = "superedge.io/node-master"

	EdgeChangeLabelKey = "superedge.io/change"

	EdgeNodeLabelValueEnable   = "enable"
	EdgeMasterLabelValueEnable = "enable"
	EdgeChangeLabelValueEnable = "enable"

	KubernetesDefaultRoleLabel  = "node-role.kubernetes.io/master"
	KubernetesControlPlaneLabel = "node-role.kubernetes.io/control-plane="
)

edgeadm

View Source
const (
	ActionChange = "change"
	ActionRevert = "revert"
)
View Source
const (
	NodeRoleNode   = "node"
	NodeRoleMaster = "master"
)
View Source
const (
	NamespaceEdgeSystem = "edge-system"
	NamespaceKubePublic = "kube-public"
)

Variables

View Source
var (
	PodNamespace = os.Getenv("POD_NAMESPACE")
)

Functions

func CertHasExpired

func CertHasExpired(cert *x509.Certificate) bool

func CopyFile added in v0.3.0

func CopyFile(sourceFile, destinationFile string) error

func DeleteSliceElement added in v0.6.1

func DeleteSliceElement(slice []string, element string) []string

func DisableEscapeJson added in v0.6.1

func DisableEscapeJson(data interface{}) (string, error)

func EncodeCertPEM

func EncodeCertPEM(cert *x509.Certificate) []byte

EncodeCertPEM returns PEM-endcoded certificate data

func GenerateCA added in v0.6.0

func GenerateCA(organization string) (caBundle string, caCert *x509.Certificate, caPrivKey *rsa.PrivateKey, err error)

func GenerateCertAndKeyConfig

func GenerateCertAndKeyConfig(caCert *x509.Certificate, caKey *rsa.PrivateKey,
	config *cert.Config) (*x509.Certificate, *rsa.PrivateKey, error)

Tobe optimized

func GenerateClientCertAndKey

func GenerateClientCertAndKey(caCert *x509.Certificate, caKey *rsa.PrivateKey,
	clientCN string) (*x509.Certificate, *rsa.PrivateKey, error)

func GetHostAllIPs added in v0.3.0

func GetHostAllIPs() (map[string]string, error)

func GetHostPublicIP added in v0.3.0

func GetHostPublicIP() (string, error)

func GetIPByInterfaceName added in v0.7.0

func GetIPByInterfaceName(name string) (ip string, err error)

func GetLocalAddrByInterface added in v0.7.0

func GetLocalAddrByInterface(name string) (net.Addr, error)

func GetLocalIP added in v0.3.0

func GetLocalIP() (string, error)

func GetRandToken

func GetRandToken(n int) string

func GetServiceCertByRootca added in v0.6.0

func GetServiceCertByRootca(commonName, organization string, dns []string, rootCA *x509.Certificate, key *rsa.PrivateKey) ([]byte, []byte, error)

func GetStringInBetween added in v0.3.0

func GetStringInBetween(str string, start string, end string) (result string)

func IsFileExist

func IsFileExist(path string) bool

func NewPrivateKey

func NewPrivateKey() (*rsa.PrivateKey, error)

NewPrivateKey creates an RSA private key change fa

func NewSignedCert

func NewSignedCert(cfg *cert.Config, key crypto.Signer,
	caCert *x509.Certificate, caKey crypto.Signer) (*x509.Certificate, error)

NewSignedCert creates a signed certificate using the given CA certificate and key

func OutPutMessage

func OutPutMessage(msg string)

func OutSuccessMessage

func OutSuccessMessage(msg string)

func ParseCertsPEM

func ParseCertsPEM(pemCerts []byte) ([]*x509.Certificate, error)

ParseCertsPEM returns the x509.Certificates contained in the given PEM-encoded byte array Returns an error if a certificate could not be parsed, or if the data does not contain any certificates

func ParsePrivateKeyPEMRSA

func ParsePrivateKeyPEMRSA(keyData []byte) (*rsa.PrivateKey, error)

func PodToYaml added in v0.7.0

func PodToYaml(pod *corev1.Pod) ([]byte, error)

func PrintFlags

func PrintFlags(flags *pflag.FlagSet)

PrintFlags logs the flags in the flagset

func ReadFile

func ReadFile(path string) ([]byte, error)

func RemoveDuplicateElement added in v0.6.1

func RemoveDuplicateElement(slice []string) []string

func RemoveFile

func RemoveFile(filePath string) error

func RunLinuxCommand added in v0.3.0

func RunLinuxCommand(command string) (string, string, error)

func RunLinuxShellFile added in v0.3.0

func RunLinuxShellFile(filename string) (string, string, error)

func SetFileContent added in v0.3.0

func SetFileContent(file, pattern, content string) string

SetFileContent generates cmd for set file content.

func SetupSignalHandler

func SetupSignalHandler() <-chan struct{}

SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned which is closed on one of these signals. If a second signal is caught, the program is terminated with exit code 1.

func SplitHostPortIgnoreMissingPort added in v0.5.0

func SplitHostPortIgnoreMissingPort(v string) (addr string, port string, err error)

func SplitHostPortWithDefaultPort added in v0.5.0

func SplitHostPortWithDefaultPort(v string, defaultPort string) (addr string, port string, err error)

func ToJson

func ToJson(v interface{}) string

func ToJsonForm

func ToJsonForm(v interface{}) string

func UpdateLogLevel

func UpdateLogLevel(w http.ResponseWriter, r *http.Request)

func WriteFile

func WriteFile(file, ctx string) error

func WriteWithAppend

func WriteWithAppend(name, content string) error

func WriteWithBufio

func WriteWithBufio(name, content string) 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