utils

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 96 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UsernameKey is the key for username in the helm repo auth secret
	UsernameKey = "username"
	// PasswordKey is the key for password in the helm repo auth secret
	PasswordKey = "password"
)

Variables

View Source
var (
	// KubeV1240Alpha4 indicates the version of Kubernetes v1.24.0-alpha.4
	KubeV1240Alpha4 = version.MustParseSemantic("v1.24.0-alpha.4")

	// KubeV1170Beta2 indicates the version of Kubernetes v1.17.0-beta.2
	KubeV1170Beta2 = version.MustParseSemantic("v1.17.0-beta.2")

	// KubeV1210Beta1 indicates the version of Kubernetes v1.21.0-beta.1
	KubeV1210Beta1 = version.MustParseSemantic("v1.21.0-beta.1")
)
View Source
var (
	Settings = cli.New()
)

Functions

func ApplyDescription added in v0.4.0

func ApplyDescription(ctx context.Context, clusternetClient *clusternetclientset.Clientset, dynamicClient dynamic.Interface,
	discoveryRESTMapper meta.RESTMapper, desc *appsapi.Description, recorder record.EventRecorder, dryApply bool,
	callbackHandler ResourceCallbackHandler, ignoreAdd bool) error

func ApplyEndPointSliceWithRetry added in v0.12.0

func ApplyEndPointSliceWithRetry(client kubernetes.Interface, slice *discoveryv1.EndpointSlice) error

ApplyEndPointSliceWithRetry create or update existed slices.

func ApplyResourceWithRetry added in v0.7.0

func ApplyResourceWithRetry(ctx context.Context, dynamicClient dynamic.Interface, restMapper meta.RESTMapper,
	resource *unstructured.Unstructured, ignoreAdd bool) error

func CheckIfInstallable added in v0.4.0

func CheckIfInstallable(chart *chart.Chart) error

CheckIfInstallable validates if a chart can be installed only application chart type is installable

func ClusterHasReadyCondition added in v0.16.0

func ClusterHasReadyCondition(mc *clusterapi.ManagedCluster) bool

func ContainsPrefix added in v0.10.0

func ContainsPrefix(slice []string, s string) bool

ContainsPrefix checks if a given slice of strings start with the provided string.

func ContainsString added in v0.2.0

func ContainsString(slice []string, s string) bool

ContainsString checks if a given slice of strings contains the provided string.

func CopyStrings added in v0.2.0

func CopyStrings(s []string) []string

CopyStrings copies the contents of the specified string slice into a new slice.

func CreateKubeConfigForSocketProxyWithToken added in v0.2.0

func CreateKubeConfigForSocketProxyWithToken(secretLister corev1lister.SecretLister,
	systemNamespace, serverURL, token string, AnonymousAuthSupported bool) (*clientcmdapi.Config, error)

CreateKubeConfigForSocketProxyWithToken creates a KubeConfig object with access to the API server with a token

func CreateKubeConfigWithToken added in v0.2.0

func CreateKubeConfigWithToken(serverURL, token string, caCert []byte) *clientcmdapi.Config

CreateKubeConfigWithToken creates a KubeConfig object with access to the API server with a token

func DeleteResourceWithRetry added in v0.5.0

func DeleteResourceWithRetry(ctx context.Context, dynamicClient dynamic.Interface, restMapper meta.RESTMapper, resource *unstructured.Unstructured) error

func DeployableByAgent added in v0.4.0

func DeployableByAgent(syncMode clusterapi.ClusterSyncMode, appPusherEnabled bool) bool

func DeployableByHub added in v0.4.0

func DeployableByHub(clusterLister clusterlisters.ManagedClusterLister, clusterID, dedicatedNamespace string) (bool, error)

DeployableByHub checks whether HelmRelease/Description should be deployed from hub

func DerivedName added in v0.12.0

func DerivedName(namespace, name string) string

func EndpointSliceV1beta1Promoted added in v0.13.0

func EndpointSliceV1beta1Promoted(kubeServerVersion string) (bool, error)

EndpointSliceV1beta1Promoted is used to indicate whether EndpointSlice v1beta1 has been promoted Keep it for legacy use.

func EnsureClusterRole added in v0.2.0

func EnsureClusterRole(ctx context.Context, clusterrole v1.ClusterRole, client *kubernetes.Clientset, backoff wait.Backoff) error

EnsureClusterRole will make sure desired clusterrole exists and update it if available

func EnsureClusterRoleBinding added in v0.2.0

func EnsureClusterRoleBinding(ctx context.Context, clusterrolebinding v1.ClusterRoleBinding, client *kubernetes.Clientset, backoff wait.Backoff) error

EnsureClusterRoleBinding will make sure desired clusterrolebinding exists and update it if available

func EnsureRole added in v0.2.0

func EnsureRole(ctx context.Context, role v1.Role, client *kubernetes.Clientset, backoff wait.Backoff) error

EnsureRole will make sure desired role exists and update it if available

func EnsureRoleBinding added in v0.2.0

func EnsureRoleBinding(ctx context.Context, rolebinding v1.RoleBinding, client *kubernetes.Clientset, backoff wait.Backoff) error

EnsureRoleBinding will make sure desired rolebinding exists and update it if available

func FindBasesFromUIDs added in v0.6.0

func FindBasesFromUIDs(baseLister applisters.BaseLister, uids []string) []*appsapi.Base

func FindOCIChart added in v0.8.0

func FindOCIChart(chartRepo, chartName, chartVersion string) (bool, error)

FindOCIChart will looks for an OCI-based helm chart from repository.

func FindObsoletedFeeds added in v0.6.0

func FindObsoletedFeeds(oldFeeds []appsapi.Feed, newFeeds []appsapi.Feed) []appsapi.Feed

func FormatFeed added in v0.4.0

func FormatFeed(feed appsapi.Feed) string

func GenerateHelmReleaseName added in v0.5.0

func GenerateHelmReleaseName(descName string, chartRef appsapi.ChartReference) string

func GenerateIdentity added in v0.7.0

func GenerateIdentity() (string, error)

func GenerateKubeConfigFromToken

func GenerateKubeConfigFromToken(serverURL, token string, caCert []byte) (*rest.Config, error)

GenerateKubeConfigFromToken composes a kubeconfig from token

func GetChildClusterConfig added in v0.3.0

func GetChildClusterConfig(
	secretLister corev1lister.SecretLister,
	clusterLister clusterlisters.ManagedClusterLister,
	namespace, clusterID, parentAPIServerURL, systemNamespace string,
	proxyingWithAnonymous bool,
) (*clientcmdapi.Config, float32, int32, error)

func GetDeployerCredentials added in v0.4.0

func GetDeployerCredentials(ctx context.Context, childKubeClientSet kubernetes.Interface, systemNamespace string, saTokenAutoGen bool) *corev1.Secret

func GetFeedKey added in v0.9.0

func GetFeedKey(feed appsapi.Feed) string

func GetHelmRepoCredentials added in v0.7.0

func GetHelmRepoCredentials(kubeclient *kubernetes.Clientset, secretName, namespace string) (string, string, error)

GetHelmRepoCredentials get helm repo credentials from the given secret

func GetLabelsSelectorFromFeed added in v0.4.0

func GetLabelsSelectorFromFeed(feed appsapi.Feed) (labels.Selector, error)

func GetPatchDataForLabelsAndAnnotations added in v0.15.0

func GetPatchDataForLabelsAndAnnotations(labels, annotations map[string]*string) ([]byte, error)

func GracefulStopWithContext

func GracefulStopWithContext() context.Context

GracefulStopWithContext registered for SIGTERM and SIGINT with a cancel context returned. When one of these signals get caught, the returned context's channel will be closed. If a second signal is caught, then the program is terminated with exit code 1.

func HasFeed added in v0.6.0

func HasFeed(feed appsapi.Feed, feeds []appsapi.Feed) bool

func HashSubscriptionSpec added in v0.7.0

func HashSubscriptionSpec(subscriptionSpec *appsapi.SubscriptionSpec) uint64

func InstallRelease added in v0.4.0

func InstallRelease(cfg *action.Configuration, hr *appsapi.HelmRelease,
	chart *chart.Chart, vals map[string]interface{}) (*release.Release, error)

func IsAttachableVolumeResourceName added in v0.10.0

func IsAttachableVolumeResourceName(name corev1.ResourceName) bool

IsAttachableVolumeResourceName returns true when the resource name is prefixed in attachable volume

func IsClusterLost added in v0.6.0

func IsClusterLost(clusterID, namespace string, clusterLister clusterlisters.ManagedClusterLister) bool

func IsExtendedResourceName added in v0.10.0

func IsExtendedResourceName(name corev1.ResourceName) bool

IsExtendedResourceName returns true if: 1. the resource name is not in the default namespace; 2. resource name does not have "requests." prefix, to avoid confusion with the convention in quota 3. it satisfies the rules in IsQualifiedName() after converted into quota resource name

func IsHugePageResourceName added in v0.10.0

func IsHugePageResourceName(name corev1.ResourceName) bool

IsHugePageResourceName returns true if the resource name has the huge page resource prefix.

func IsNativeResource added in v0.10.0

func IsNativeResource(name corev1.ResourceName) bool

IsNativeResource returns true if the resource name is in the *kubernetes.io/ namespace. Partially-qualified (unprefixed) names are implicitly in the kubernetes.io/ namespace.

func IsPrefixedNativeResource added in v0.10.0

func IsPrefixedNativeResource(name corev1.ResourceName) bool

IsPrefixedNativeResource returns true if the resource name is in the *kubernetes.io/ namespace.

func IsScalarResourceName added in v0.10.0

func IsScalarResourceName(name corev1.ResourceName) bool

IsScalarResourceName validates the resource for Extended, Hugepages, Native and AttachableVolume resources

func ListManifestsBySelector added in v0.4.0

func ListManifestsBySelector(reservedNamespace string, manifestLister applisters.ManifestLister, feed appsapi.Feed) ([]*appsapi.Manifest, error)

func LoadsKubeConfig

func LoadsKubeConfig(clientConnectionCfg *componentbaseconfig.ClientConnectionConfiguration) (*rest.Config, error)

LoadsKubeConfig tries to load kubeconfig from specified kubeconfig file or in-cluster config

func LoadsKubeConfigFromFile added in v0.12.0

func LoadsKubeConfigFromFile(fileName string) (*rest.Config, error)

LoadsKubeConfigFromFile tries to load kubeconfig from specified kubeconfig file

func LocateAuthHelmChart added in v0.7.0

func LocateAuthHelmChart(cfg *action.Configuration, chartRepo, username, password, chartName, chartVersion string) (*chart.Chart, error)

LocateAuthHelmChart will looks for a chart from auth repository and load it.

func MaxInt added in v0.10.0

func MaxInt(a, b int) int

func MaxInt32 added in v0.10.0

func MaxInt32(a, b int32) int32

func MinInt added in v0.10.0

func MinInt(a, b int) int

func MinInt32 added in v0.10.0

func MinInt32(a, b int32) int32

func MinInt64 added in v0.10.0

func MinInt64(a, b int64) int64

func MultiClusterServiceEnabled added in v0.15.0

func MultiClusterServiceEnabled(kubeServerVersion string) (bool, error)

MultiClusterServiceEnabled is used to indicate whether EndpointSlice v1 has been promoted

func NewHealthzAndMetricsHandler added in v0.15.0

func NewHealthzAndMetricsHandler(name string, debuggingOptions *controllermanageroptions.DebuggingOptions, checks ...healthz.HealthChecker) http.Handler

NewHealthzAndMetricsHandler creates a healthz server from the config, and will also embed the metrics handler.

func NewLeaderElectionConfigWithDefaultValue added in v0.7.0

func NewLeaderElectionConfigWithDefaultValue(identity, leaseName, leaseNamespace string,
	leaseDuration time.Duration, renewDeadline time.Duration, retryPeriod time.Duration,
	clientset kubernetes.Interface, callbacks leaderelection.LeaderCallbacks) *leaderelection.LeaderElectionConfig

func NewResourceInformer added in v0.7.0

func NewResourceInformer(client ResourceClient, apiResource *metav1.APIResource,
	handler cache.ResourceEventHandlerFuncs) (*resourceInformer, error)

NewResourceInformer returns a filtered informer limited to resources managed by Clusternet as indicated by labeling.

func OffloadDescription added in v0.4.0

func OffloadDescription(ctx context.Context, clusternetClient *clusternetclientset.Clientset, dynamicClient dynamic.Interface,
	discoveryRESTMapper meta.RESTMapper, desc *appsapi.Description, recorder record.EventRecorder) error

func PatchHelmChartLabelsAndAnnotations added in v0.4.0

func PatchHelmChartLabelsAndAnnotations(clusternetClient *clusternetclientset.Clientset, chart *appsapi.HelmChart,
	labels, annotations map[string]*string) error

func PatchManifestLabelsAndAnnotations added in v0.4.0

func PatchManifestLabelsAndAnnotations(clusternetClient *clusternetclientset.Clientset, manifest *appsapi.Manifest,
	labels, annotations map[string]*string) error

func ReconcileHelmRelease added in v0.4.0

func ReconcileHelmRelease(ctx context.Context, deployCtx *DeployContext, kubeClient *kubernetes.Clientset,
	clusternetClient *clusternetclientset.Clientset,
	hrLister applisters.HelmReleaseLister, descLister applisters.DescriptionLister,
	hr *appsapi.HelmRelease, recorder record.EventRecorder) error

func ReleaseNeedsUpgrade added in v0.4.0

func ReleaseNeedsUpgrade(rel *release.Release, hr *appsapi.HelmRelease, chart *chart.Chart, vals map[string]interface{}) bool

func RemoveFeedFromSubscription added in v0.4.0

func RemoveFeedFromSubscription(ctx context.Context, clusternetClient *clusternetclientset.Clientset,
	feedSourceLabels map[string]string, sub *appsapi.Subscription) error

func RemoveString added in v0.2.0

func RemoveString(slice []string, s string) []string

RemoveString returns a newly created []string that contains all items from slice that are not equal to s.

func RemoveUnexistEndpointslice added in v0.12.0

func RemoveUnexistEndpointslice(srcLister discoverylisterv1.EndpointSliceLister, srcNamespace string, labelMap labels.Set,
	targetClient kubernetes.Interface, targetNamespace string, dstLabelMap labels.Set) ([]*discoveryv1.EndpointSlice, error)

func ResourceNeedResync added in v0.7.0

func ResourceNeedResync(current pkgruntime.Object, modified pkgruntime.Object, ignoreAdd bool) bool

ResourceNeedResync will compare fields and decide whether to sync back the current object.

current is deployed resource, modified is changed resource. ignoreAdd is true if you want to ignore add action. The function will return the bool value to indicate whether to sync back the current object.

func SATokenAutoGenerated added in v0.13.0

func SATokenAutoGenerated(kubeServerVersion string) (bool, error)

SATokenAutoGenerated is used to indicate whether secret-based service account token can be auto generated

func SortStrings added in v0.2.0

func SortStrings(s []string) []string

SortStrings sorts the specified string slice in place. It returns the same slice that was provided in order to facilitate method chaining.

func SumArrayInt32 added in v0.11.0

func SumArrayInt32(array []int32) (sum int32)

func UninstallRelease added in v0.4.0

func UninstallRelease(cfg *action.Configuration, hr *appsapi.HelmRelease) error

func UpdateDescriptionStatus added in v0.11.0

func UpdateDescriptionStatus(desc *appsapi.Description, status *appsapi.DescriptionStatus, clusternetClient *clusternetclientset.Clientset, deployerTrigger bool) error

func UpdateHelmReleaseStatus added in v0.4.0

func UpdateHelmReleaseStatus(ctx context.Context, clusternetClient *clusternetclientset.Clientset,
	hrLister applisters.HelmReleaseLister, descLister applisters.DescriptionLister,
	hr *appsapi.HelmRelease, status *appsapi.HelmReleaseStatus) error

func UpdateRepo added in v0.4.0

func UpdateRepo(repoURL string) error

func UpgradeRelease added in v0.4.0

func UpgradeRelease(cfg *action.Configuration, hr *appsapi.HelmRelease,
	chart *chart.Chart, vals map[string]interface{}) (*release.Release, error)

Types

type ControllerOptions added in v0.7.0

type ControllerOptions struct {
	// LeaderElection defines the configuration of leader election client.
	LeaderElection componentbaseconfig.LeaderElectionConfiguration

	// ClientConnection specifies the kubeconfig file and client connection
	// settings for the proxy server to use when communicating with the apiserver.
	ClientConnection componentbaseconfig.ClientConnectionConfiguration

	Logs *logs.Options
}

ControllerOptions has all the params needed to run a Controller

func NewControllerOptions added in v0.7.0

func NewControllerOptions(resourceName, resourceNamespace string) (*ControllerOptions, error)

NewControllerOptions returns a new ControllerOptions

func (*ControllerOptions) AddFlagSets added in v0.15.0

func (o *ControllerOptions) AddFlagSets(fss *cliflag.NamedFlagSets)

func (*ControllerOptions) Complete added in v0.7.0

func (o *ControllerOptions) Complete() error

Complete fills in fields required to have valid data

func (*ControllerOptions) Validate added in v0.7.0

func (o *ControllerOptions) Validate() error

Validate validates ControllerOptions

type DeployContext added in v0.4.0

type DeployContext struct {
	// contains filtered or unexported fields
}

func NewDeployContext added in v0.4.0

func NewDeployContext(config *clientcmdapi.Config, kubeQPS float32, kubeBurst int32) (*DeployContext, error)

func (*DeployContext) ToDiscoveryClient added in v0.4.0

func (dctx *DeployContext) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*DeployContext) ToRESTConfig added in v0.4.0

func (dctx *DeployContext) ToRESTConfig() (*rest.Config, error)

func (*DeployContext) ToRESTMapper added in v0.4.0

func (dctx *DeployContext) ToRESTMapper() (meta.RESTMapper, error)

func (*DeployContext) ToRawKubeConfigLoader added in v0.4.0

func (dctx *DeployContext) ToRawKubeConfigLoader() clientcmd.ClientConfig

type JsonPatchOption added in v0.4.0

type JsonPatchOption struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value,omitempty"`
}

type MetaData added in v0.4.0

type MetaData struct {
	Labels      map[string]*string `json:"labels,omitempty"`
	Annotations map[string]*string `json:"annotations,omitempty"`
}

type MetaOption added in v0.4.0

type MetaOption struct {
	MetaData MetaData `json:"metadata"`
}

type Resource added in v0.10.0

type Resource struct {
	MilliCPU         int64
	Memory           int64
	EphemeralStorage int64
	AllowedPodNumber int64
	// ScalarResources
	ScalarResources map[corev1.ResourceName]int64
}

Resource is a collection of compute resource.

func EmptyResource added in v0.10.0

func EmptyResource() *Resource

EmptyResource creates a empty resource object and returns.

func NewResource added in v0.10.0

func NewResource(rl corev1.ResourceList) *Resource

func (*Resource) Add added in v0.10.0

func (r *Resource) Add(rl corev1.ResourceList)

Add is used to add two resources.

func (*Resource) AddMulti added in v0.10.0

func (r *Resource) AddMulti(rl corev1.ResourceList, ratio int64)

AddMulti is used to add resources with scale.

func (*Resource) AddPodRequest added in v0.10.0

func (r *Resource) AddPodRequest(podSpec *corev1.PodSpec) *Resource

AddPodRequest add the effective request resource of a pod to the origin resource. The Pod's effective request is the higher of: - the sum of all app containers(spec.Containers) request for a resource. - the effective init containers(spec.InitContainers) request for a resource. The effective init containers request is the highest request on all init containers.

func (*Resource) AddResourcePods added in v0.10.0

func (r *Resource) AddResourcePods(pods int64)

func (*Resource) AddScalar added in v0.10.0

func (r *Resource) AddScalar(name corev1.ResourceName, quantity int64)

AddScalar adds a resource by a scalar value of this resource.

func (*Resource) Clone added in v0.10.0

func (r *Resource) Clone() *Resource

Clone is used to clone a resource type, which is a deep copy function.

func (*Resource) Less added in v0.10.0

func (r *Resource) Less(rr *Resource) bool

func (*Resource) MaxReplicaDivided added in v0.10.0

func (r *Resource) MaxReplicaDivided(rl corev1.ResourceList) int64

func (*Resource) Multi added in v0.10.0

func (r *Resource) Multi(ratio int64)

Multi is used to scale a resource.

func (*Resource) ResourceList added in v0.10.0

func (r *Resource) ResourceList() corev1.ResourceList

ResourceList returns a resource list of this resource.

func (*Resource) SetMaxResource added in v0.10.0

func (r *Resource) SetMaxResource(rl corev1.ResourceList)

SetMaxResource compares with ResourceList and takes max value for each Resource.

func (*Resource) SetScalar added in v0.10.0

func (r *Resource) SetScalar(name corev1.ResourceName, quantity int64)

SetScalar sets a resource by a scalar value of this resource.

func (*Resource) String added in v0.10.0

func (r *Resource) String() string

String returns resource details in string format

func (*Resource) Sub added in v0.10.0

func (r *Resource) Sub(rl corev1.ResourceList) error

Sub is used to subtract two resources.

type ResourceCallbackHandler added in v0.7.0

type ResourceCallbackHandler func(resource *unstructured.Unstructured) error

type ResourceClient added in v0.7.0

type ResourceClient interface {
	Resources(namespace string) dynamic.ResourceInterface
	Kind() string
}

func NewResourceClient added in v0.7.0

func NewResourceClient(client dynamic.Interface, apiResource *metav1.APIResource) ResourceClient

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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