utils

package
v0.0.0-...-ec72bf4 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

* Copyright (c) 2023 Baidu, Inc. All Rights Reserved. * * 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

This section is empty.

Variables

This section is empty.

Functions

func ConvertPrivateIP2AddressPair

func ConvertPrivateIP2AddressPair(privateIP *models.PrivateIP, subnet *ccev1.Subnet) (*ccev2.AddressPair, error)

ConvertPrivateIP2AddressPair converts private ip to address pair

func ExtractNamespace

func ExtractNamespace(np NamespaceNameGetter) string

ExtractNamespace extracts the namespace of ObjectMeta. For cluster scoped objects the Namespace field is empty and this function assumes that the object is returned from kubernetes itself implying that the namespace is empty only and only when the Object is cluster scoped and thus returns empty namespace for such objects.

func ExtractNamespaceOrDefault

func ExtractNamespaceOrDefault(np NamespaceNameGetter) string

ExtractNamespaceOrDefault extracts the namespace of ObjectMeta, it returns default namespace if the namespace field in the ObjectMeta is empty.

func GetClusterIPByFamily

func GetClusterIPByFamily(ipFamily corev1.IPFamily, service *corev1.Service) string

GetClusterIPByFamily returns a service clusterip by family. From - https://github.com/kubernetes/kubernetes/blob/release-1.20/pkg/proxy/util/utils.go#L386-L411

func GetLatestPodReadiness

func GetLatestPodReadiness(podStatus corev1.PodStatus) corev1.ConditionStatus

GetLatestPodReadiness returns the lastest podReady condition on a given pod.

func GetObjNamespaceName

func GetObjNamespaceName(obj NamespaceNameGetter) string

GetObjNamespaceName returns the object's namespace and name. If the object is cluster scoped then the function returns only the object name without any namespace prefix.

func GetServiceListOptionsModifier

func GetServiceListOptionsModifier(cfg ServiceConfiguration) (func(options *v1meta.ListOptions), error)

GetServiceListOptionsModifier returns the options modifier for service object list. This methods returns a ListOptions modifier which adds a label selector to only select services that are in context of CCE. Like kube-proxy CCE does not select services containing k8s headless service label. We honor service.kubernetes.io/service-proxy-name label in the service object and only handle services that match our service proxy name. If the service proxy name for CCE is an empty string, we assume that CCE is the default service handler in which case we select all services that don't have the above mentioned label.

func IsPodRunning

func IsPodRunning(status corev1.PodStatus) bool

IsPodRunning returns true if the pod is considered to be in running state. We consider a Running pod a pod that does not report a Failed nor a Succeeded pod Phase.

func ValidIPs

func ValidIPs(podStatus corev1.PodStatus) []string

ValidIPs return a sorted slice of unique IP addresses retrieved from the given PodStatus. Returns an error when no IPs are found.

Types

type IngressConfiguration

type IngressConfiguration interface {
	// K8sIngressControllerEnabled returns true if ingress controller feature is enabled in CCE
	K8sIngressControllerEnabled() bool
}

IngressConfiguration is the required configuration for GetServiceListOptionsModifier

type NamespaceNameGetter

type NamespaceNameGetter interface {
	GetNamespace() string
	GetName() string
}

type ServiceConfiguration

type ServiceConfiguration interface {
	// K8sServiceProxyNameValue must return the value of the proxy name
	// annotation. If set, only services with this label will be handled.
	K8sServiceProxyNameValue() string
}

ServiceConfiguration is the required configuration for GetServiceListOptionsModifier

Jump to

Keyboard shortcuts

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