util

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRSABits = 2048
	// For now the ClusterControlPlane API doesn't support rotating certificate. We set long valid time to avoid certificate expiration.
	DefaultValidDays             = 3650
	DefaultValidDaysWithRotation = 365
	DefaultRotateDays            = 7
	DefaultSerialNumberLength    = 160
)
View Source
const (
	HashLength          int = 8
	SubnetTypeSubnet        = "subnet"
	SubnetTypeSubnetSet     = "subnetset"
)

Variables

View Source
var (
	DefaultSubject = pkix.Name{
		Country:            []string{"US"},
		Organization:       []string{"VMware"},
		OrganizationalUnit: []string{"Antrea Cluster"},
		Locality:           []string{"Palo Alto"},
		Province:           []string{"CA"},
		CommonName:         "dummy",
	}
)
View Source
var (
	String = common.String
)

Functions

func AppendTags

func AppendTags(basicTags, extraTags []model.Tag) []model.Tag

func BuildBasicTags

func BuildBasicTags(cluster string, obj interface{}, namespaceID types.UID) []model.Tag

func CalculateIPFromCIDRs

func CalculateIPFromCIDRs(IPAddresses []string) (int, error)

func CalculateSubnetSize

func CalculateSubnetSize(mask int) int64

func Capitalize

func Capitalize(s string) string

func CheckPodHasNamedPort

func CheckPodHasNamedPort(pod v1.Pod, reason string) bool

CheckPodHasNamedPort checks if the pod has a named port, it filters the pod events we don't want give concern.

func Contains

func Contains(s []string, str string) bool

func GenerateCertificate

func GenerateCertificate(subject *pkix.Name, validDays int) (string, string, error)

GenerateCertificate returns generated certificate and private key in PEM format

func GenerateDisplayName

func GenerateDisplayName(res_name, prefix, suffix, project, cluster string) string

func GenerateID

func GenerateID(res_id, prefix, suffix string, index string) string

GenerateID generate id for nsx resource, some resources has complex index, so set it type to string

func GenerateTruncName

func GenerateTruncName(limit int, res_name, prefix, suffix, project, cluster string) string

func GetIPPrefix

func GetIPPrefix(ipAddress string) (int, error)

GetIPPrefix get the prefix from an IP address, e.g. "1.2.3.4/24" -> 24

func GetMapValues

func GetMapValues(in interface{}) []string

func GetSubnetMask

func GetSubnetMask(subnetLength int) (string, error)

GetSubnetMask get the mask for a given prefix length, e.g. 24 -> "255.255.255.0"

func If

func If(condition bool, trueVal, falseVal interface{}) interface{}

func IsSystemNamespace

func IsSystemNamespace(c client.Client, ns string, obj *v1.Namespace) (bool, error)

func NormalizeId

func NormalizeId(name string) string

func NormalizeLabelKey

func NormalizeLabelKey(key string) string

func NormalizeLabels

func NormalizeLabels(matchLabels *map[string]string) *map[string]string

func NormalizeName

func NormalizeName(name string) string

func RemoveDuplicateStr

func RemoveDuplicateStr(strSlice []string) []string

func RemoveIPPrefix

func RemoveIPPrefix(ipAddress string) (string, error)

RemoveIPPrefix remove the prefix from an IP address, e.g. "1.2.3.4/24" -> "1.2.3.4"

func Sha1

func Sha1(data string) string

func ToUpper

func ToUpper(obj interface{}) string

func UpdateK8sResourceAnnotation

func UpdateK8sResourceAnnotation(client client.Client, ctx *context.Context, k8sObj client.Object, changes map[string]string) error

the changes map contains key/value map that you want to change. if giving empty value for a key in changes map like: "mykey":"", that means removing this annotation from k8s resource

Types

This section is empty.

Jump to

Keyboard shortcuts

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