Documentation ¶
Overview ¶
Package utils provides generic utility routines used within FSM.
Index ¶
- func CertToPEM(caBytes []byte) ([]byte, error)
- func ConvertPEMCertToX509(pemCrt []byte) (*x509.Certificate, error)
- func ConvertPEMPrivateKeyToX509(pemKey []byte) (*rsa.PrivateKey, error)
- func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object) (controllerutil.OperationResult, error)
- func CreateOrUpdateUnstructured(ctx context.Context, dynamicClient dynamic.Interface, mapper meta.RESTMapper, ...) error
- func CsrToPEM(csrBytes []byte) ([]byte, error)
- func DecodeYamlToUnstructured(data []byte) (*unstructured.Unstructured, error)
- func DeleteUnstructured(ctx context.Context, dynamicClient dynamic.Interface, mapper meta.RESTMapper, ...) error
- func ErrorListToError(errorList field.ErrorList) error
- func EvaluateTemplate(t *template.Template, data interface{}) string
- func FilterByIPFamily(ips []string, svc *corev1.Service) ([]string, error)
- func GatewayCodebasePath(namespace string) string
- func GenerateRandom(n int) string
- func GetBytes(key interface{}) ([]byte, error)
- func GetDefaultGatewaysPath() string
- func GetDefaultIngressPath() string
- func GetDefaultServicesPath() string
- func GetEnv(envVar string, defaultValue string) string
- func GetIPFromContext(ctx context.Context) net.Addr
- func GetLastChunkOfSlashed(s string) string
- func GetSecretDataHash(secret *corev1.Secret) uint32
- func GrpcServe(ctx context.Context, grpcServer *grpc.Server, lis net.Listener, ...)
- func Hash(bytes []byte) uint64
- func HashFNV(s string) string
- func HashFromString(s string) (uint64, error)
- func IP2Int(ip net.IP) *big.Int
- func ImagePullPolicyByTag(image string) corev1.PullPolicy
- func IngressCodebasePath() string
- func Int2IP16(nn uint64) net.IP
- func Int2IP4(nn uint32) net.IP
- func IsPodStatusConditionPresentAndEqual(conditions []corev1.PodCondition, conditionType corev1.PodConditionType, ...) bool
- func IsPodStatusConditionTrue(conditions []corev1.PodCondition, conditionType corev1.PodConditionType) bool
- func NamespacedIngressCodebasePath(namespace string) string
- func NewGrpc(serverType string, port int, certPem, keyPem, rootCertPem []byte) (*grpc.Server, net.Listener, error)
- func ParseEnabled(enabled string) bool
- func ParseImageName(image string) (string, string, string, error)
- func PipyLogLevelByVerbosity(verbosity string) string
- func PrettyJSON(js []byte, prefix string) ([]byte, error)
- func RSAKeyToPEM(privateKey *rsa.PrivateKey) ([]byte, error)
- func RegisterExitHandlers(shutdownFuncs ...func()) (stop chan struct{})
- func RegisterOSExitHandlers(shutdownFuncs ...func()) (stop chan struct{})
- func SecretNamespaceAndName(secretName string, ing *networkingv1.Ingress) (string, string, error)
- func SimpleHash(obj interface{}) string
- func StringsEqual(left, right []string) bool
- func SvcAccountToK8sSvcAccount(svcAccount *corev1.ServiceAccount) identity.K8sServiceAccount
- func ValidateClient(ctx context.Context) (certificate.CommonName, certificate.SerialNumber, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertPEMCertToX509 ¶ added in v1.1.0
func ConvertPEMCertToX509(pemCrt []byte) (*x509.Certificate, error)
ConvertPEMCertToX509 converts a PEM certificate to x509
func ConvertPEMPrivateKeyToX509 ¶ added in v1.1.0
func ConvertPEMPrivateKeyToX509(pemKey []byte) (*rsa.PrivateKey, error)
ConvertPEMPrivateKeyToX509 converts a PEM private key to x509
func CreateOrUpdate ¶ added in v1.1.0
func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object) (controllerutil.OperationResult, error)
CreateOrUpdate creates or updates the object
func CreateOrUpdateUnstructured ¶ added in v1.1.1
func CreateOrUpdateUnstructured(ctx context.Context, dynamicClient dynamic.Interface, mapper meta.RESTMapper, obj *unstructured.Unstructured) error
func DecodeYamlToUnstructured ¶ added in v1.1.0
func DecodeYamlToUnstructured(data []byte) (*unstructured.Unstructured, error)
DecodeYamlToUnstructured decodes YAML to Unstructured
func DeleteUnstructured ¶ added in v1.1.1
func DeleteUnstructured(ctx context.Context, dynamicClient dynamic.Interface, mapper meta.RESTMapper, obj *unstructured.Unstructured) error
func ErrorListToError ¶ added in v1.1.0
ErrorListToError converts a list of errors to a single error
func EvaluateTemplate ¶ added in v1.1.0
EvaluateTemplate evaluates the given template with the given data and returns the result as a string.
func FilterByIPFamily ¶ added in v1.2.0
FilterByIPFamily filters the given list of IPs by the IPFamilyPolicy of the given service.
func GatewayCodebasePath ¶ added in v1.1.0
GatewayCodebasePath get the codebase URL for the gateway in specified namespace inherit hierarchy: /base/gateways -> /local/gateways -> /local/gw/[ns]
func GenerateRandom ¶ added in v1.1.0
GenerateRandom generates random string.
func GetDefaultGatewaysPath ¶ added in v1.1.0
func GetDefaultGatewaysPath() string
GetDefaultGatewaysPath returns the path to the gateways codebase. inherit hierarchy: /base/gateways -> /local/gateways -> /local/gw/[ns]
func GetDefaultIngressPath ¶ added in v1.1.0
func GetDefaultIngressPath() string
GetDefaultIngressPath returns the path to the ingress codebase.
func GetDefaultServicesPath ¶ added in v1.1.0
func GetDefaultServicesPath() string
GetDefaultServicesPath returns the path to the services codebase.
func GetEnv ¶
GetEnv is a convenience wrapper for os.Getenv() with additional default value return when empty or unset
func GetIPFromContext ¶
GetIPFromContext obtains the IP address of the caller from the context.
func GetLastChunkOfSlashed ¶
GetLastChunkOfSlashed splits a string by slash and returns the last chunk.
func GetSecretDataHash ¶ added in v1.1.0
GetSecretDataHash returns a hash of the given secret data.
func GrpcServe ¶
func GrpcServe(ctx context.Context, grpcServer *grpc.Server, lis net.Listener, cancel context.CancelFunc, serverType string, errorCh chan interface{})
GrpcServe starts the gRPC server passed.
func HashFromString ¶
HashFromString calculates an FNV-1 hash from a given string, returns it as a uint64 and error, if any
func ImagePullPolicyByTag ¶ added in v1.1.0
func ImagePullPolicyByTag(image string) corev1.PullPolicy
ImagePullPolicyByTag returns the pull policy for the given image tag.
func IngressCodebasePath ¶ added in v1.1.0
func IngressCodebasePath() string
IngressCodebasePath returns the path to the ingress codebase.
func IsPodStatusConditionPresentAndEqual ¶ added in v1.2.0
func IsPodStatusConditionPresentAndEqual(conditions []corev1.PodCondition, conditionType corev1.PodConditionType, status corev1.ConditionStatus) bool
IsPodStatusConditionPresentAndEqual returns true if the pod has the given condition and status.
func IsPodStatusConditionTrue ¶ added in v1.2.0
func IsPodStatusConditionTrue(conditions []corev1.PodCondition, conditionType corev1.PodConditionType) bool
IsPodStatusConditionTrue returns true if the pod is ready.
func NamespacedIngressCodebasePath ¶ added in v1.1.0
NamespacedIngressCodebasePath returns the path to the ingress codebase for the given namespace.
func NewGrpc ¶
func NewGrpc(serverType string, port int, certPem, keyPem, rootCertPem []byte) (*grpc.Server, net.Listener, error)
NewGrpc creates a new gRPC server
func ParseEnabled ¶ added in v1.1.0
ParseEnabled parses the given string to a boolean value.
func ParseImageName ¶ added in v1.1.0
ParseImageName parses a docker image string into three parts: repo, tag and digest. If both tag and digest are empty, a default image tag will be returned.
func PipyLogLevelByVerbosity ¶ added in v1.1.1
func PrettyJSON ¶
PrettyJSON Unmarshals and Marshall again with Indent so it is human readable
func RSAKeyToPEM ¶ added in v1.1.0
func RSAKeyToPEM(privateKey *rsa.PrivateKey) ([]byte, error)
RSAKeyToPEM converts a RSA private key to PEM format
func RegisterExitHandlers ¶ added in v1.1.0
func RegisterExitHandlers(shutdownFuncs ...func()) (stop chan struct{})
RegisterExitHandlers registers a shutdown function to be called when a signal is received.
func RegisterOSExitHandlers ¶ added in v1.1.0
func RegisterOSExitHandlers(shutdownFuncs ...func()) (stop chan struct{})
RegisterOSExitHandlers registers a shutdown function to be called when a signal is received.
func SecretNamespaceAndName ¶ added in v1.1.0
SecretNamespaceAndName returns the namespace and name of the secret.
func SimpleHash ¶ added in v1.1.0
func SimpleHash(obj interface{}) string
SimpleHash returns a hash string of the given object.
func StringsEqual ¶ added in v1.1.0
StringsEqual compares two string slices and returns true if they are equal.
func SvcAccountToK8sSvcAccount ¶
func SvcAccountToK8sSvcAccount(svcAccount *corev1.ServiceAccount) identity.K8sServiceAccount
SvcAccountToK8sSvcAccount converts a Kubernetes service to a MeshService.
func ValidateClient ¶
func ValidateClient(ctx context.Context) (certificate.CommonName, certificate.SerialNumber, error)
ValidateClient ensures that the connected client is authorized to connect to the gRPC server.
Types ¶
This section is empty.