addonfactory

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 32 Imported by: 31

Documentation

Index

Constants

View Source
const AddonDefaultInstallNamespace = "open-cluster-management-agent-addon"
View Source
const AnnotationValuesName string = "addon.open-cluster-management.io/values"

AnnotationValuesName is the annotation Name of customized values

Variables

View Source
var AddOnDeploymentConfigGVR = schema.GroupVersionResource{
	Group:    "addon.open-cluster-management.io",
	Version:  "v1alpha1",
	Resource: "addondeploymentconfigs",
}

Deprecated: use AddOnDeploymentConfigGVR in package "open-cluster-management.io/addon-framework/pkg/utils" instead.

Functions

func NewAddOnDeloymentConfigGetter added in v0.5.0

func NewAddOnDeloymentConfigGetter(addonClient addonv1alpha1client.Interface) utils.AddOnDeploymentConfigGetter

NewAddOnDeloymentConfigGetter returns a AddOnDeloymentConfigGetter with addon client Deprecated: use NewAddOnDeploymentConfigGetter in pkg/utils package instead.

func NewAddOnDeploymentConfigGetter added in v0.6.1

func NewAddOnDeploymentConfigGetter(addonClient addonv1alpha1client.Interface) utils.AddOnDeploymentConfigGetter

NewAddOnDeploymentConfigGetter returns a AddOnDeploymentConfigGetter with addon client Deprecated: use NewAddOnDeploymentConfigGetter in pkg/utils package instead.

func NewFakeManagedCluster

func NewFakeManagedCluster(name string, k8sVersion string) *clusterv1.ManagedCluster

func NewFakeManagedClusterAddon

func NewFakeManagedClusterAddon(name, clusterName, installNamespace, values string) *addonapiv1alpha1.ManagedClusterAddOn

func OverrideImage added in v0.8.0

func OverrideImage(registries []addonapiv1alpha1.ImageMirror, imageName string) string

OverrideImage checks whether the source configured in registries can match the imagedName, if yes will use the mirror value in the registries to override the imageName

Types

type AddOnDeloymentConfigToValuesFunc added in v0.5.0

type AddOnDeloymentConfigToValuesFunc func(config addonapiv1alpha1.AddOnDeploymentConfig) (Values, error)

AddOnDeloymentConfigToValuesFunc transform the AddOnDeploymentConfig object into Values object The transformation logic depends on the definition of the addon template Deprecated: use AddOnDeploymentConfigToValuesFunc instead.

type AddOnDeploymentConfigToValuesFunc added in v0.6.1

type AddOnDeploymentConfigToValuesFunc func(config addonapiv1alpha1.AddOnDeploymentConfig) (Values, error)

AddOnDeploymentConfigToValuesFunc transform the AddOnDeploymentConfig object into Values object The transformation logic depends on the definition of the addon template

func ToImageOverrideValuesFunc added in v0.8.0

func ToImageOverrideValuesFunc(imageKey, image string) AddOnDeploymentConfigToValuesFunc

ToImageOverrideValuesFunc return a func that can use the AddOnDeploymentConfig.spec.Registries to override image, then return the overridden value with key imageKey.

for example: the spec of one AddOnDeploymentConfig is: { registries: [{source: "quay.io/open-cluster-management/addon-agent", mirror: "quay.io/ocm/addon-agent"}]} the imageKey is "helloWorldImage", the image is "quay.io/open-cluster-management/addon-agent:v1" after transformed, the Values object will be: {"helloWorldImage": "quay.io/ocm/addon-agent:v1"}

Note:

  • the imageKey can support the nested key, for example: "global.imageOverrides.helloWorldImage", the output will be: {"global": {"imageOverrides": {"helloWorldImage": "quay.io/ocm/addon-agent:v1"}}}
  • If you want to override the image with the value from the AddOnDeploymentConfig.spec.Registries first, and if it is not changed, then override it with the value from the cluster annotation, you can use the function GetAgentImageValues instead.

type AgentAddonFactory

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

AgentAddonFactory includes the common fields for building different agentAddon instances.

func NewAgentAddonFactory

func NewAgentAddonFactory(addonName string, fs embed.FS, dir string) *AgentAddonFactory

NewAgentAddonFactory builds an addonAgentFactory instance with addon name and fs. dir is the path prefix based on the fs path.

func (*AgentAddonFactory) BuildHelmAgentAddon

func (f *AgentAddonFactory) BuildHelmAgentAddon() (agent.AgentAddon, error)

BuildHelmAgentAddon builds a helm agentAddon instance.

func (*AgentAddonFactory) BuildTemplateAgentAddon

func (f *AgentAddonFactory) BuildTemplateAgentAddon() (agent.AgentAddon, error)

BuildTemplateAgentAddon builds a template agentAddon instance.

func (*AgentAddonFactory) WithAgentDeployTriggerClusterFilter added in v0.8.0

func (f *AgentAddonFactory) WithAgentDeployTriggerClusterFilter(
	filter func(old, new *clusterv1.ManagedCluster) bool,
) *AgentAddonFactory

WithAgentDeployTriggerClusterFilter defines the filter func to trigger the agent deploy/redploy when cluster info is changed. Addons that need information from the ManagedCluster resource when deploying the agent should use this function to set what information they need, otherwise the expected/up-to-date agent may be deployed delayed since the default filter func returns false when the ManagedCluster resource is updated.

For example, the agentAddon needs information from the ManagedCluster annotation, it can set the filter function like:

WithAgentDeployClusterTriggerFilter(func(old, new *clusterv1.ManagedCluster) bool {
 return !equality.Semantic.DeepEqual(old.Annotations, new.Annotations)
})

func (*AgentAddonFactory) WithAgentHealthProber added in v0.4.0

func (f *AgentAddonFactory) WithAgentHealthProber(prober *agent.HealthProber) *AgentAddonFactory

WithAgentHealthProber defines how is the healthiness status of the ManagedClusterAddon probed.

func (*AgentAddonFactory) WithAgentHostedModeEnabledOption added in v0.5.0

func (f *AgentAddonFactory) WithAgentHostedModeEnabledOption() *AgentAddonFactory

WithAgentHostedModeEnabledOption will enable the agent hosted deploying mode.

func (*AgentAddonFactory) WithAgentInstallNamespace added in v0.9.0

func (f *AgentAddonFactory) WithAgentInstallNamespace(
	nsFunc func(addon *addonapiv1alpha1.ManagedClusterAddOn) (string, error),
) *AgentAddonFactory

WithAgentInstallNamespace defines the namespace where the agent resources will be deployed, this will override the default built-in namespace value; And if the registrationOption is not nil but the registrationOption.AgentInstallNamespace is nil, this will also set it to this.

func (*AgentAddonFactory) WithAgentRegistrationOption

func (f *AgentAddonFactory) WithAgentRegistrationOption(option *agent.RegistrationOption) *AgentAddonFactory

WithAgentRegistrationOption defines how agent is registered to the hub cluster.

func (*AgentAddonFactory) WithConfigGVRs added in v0.5.0

func (f *AgentAddonFactory) WithConfigGVRs(gvrs ...schema.GroupVersionResource) *AgentAddonFactory

WithConfigGVRs defines the addon supported configuration GroupVersionResource

func (*AgentAddonFactory) WithGetValuesFuncs

func (f *AgentAddonFactory) WithGetValuesFuncs(getValuesFuncs ...GetValuesFunc) *AgentAddonFactory

WithGetValuesFuncs adds a list of the getValues func. the values got from the big index Func will override the one from small index Func.

func (*AgentAddonFactory) WithHostingCluster added in v0.6.1

func (f *AgentAddonFactory) WithHostingCluster(cluster *clusterv1.ManagedCluster) *AgentAddonFactory

WithHostingCluster defines the hosting cluster used in hosted mode. An AgentAddon may use this to provide additional metadata.

func (*AgentAddonFactory) WithInstallStrategy

func (f *AgentAddonFactory) WithInstallStrategy(strategy *agent.InstallStrategy) *AgentAddonFactory

WithInstallStrategy defines the installation strategy of the manifests prescribed by Manifests(..). Deprecated: add annotation "addon.open-cluster-management.io/lifecycle: addon-manager" to ClusterManagementAddon and define install strategy in ClusterManagementAddon spec.installStrategy instead. The migration plan refer to https://github.com/open-cluster-management-io/ocm/issues/355.

func (*AgentAddonFactory) WithScheme

WithScheme is an optional configuration, only used when the agentAddon has customized resource types.

func (*AgentAddonFactory) WithTrimCRDDescription

func (f *AgentAddonFactory) WithTrimCRDDescription() *AgentAddonFactory

WithTrimCRDDescription is to enable trim the description of CRDs in manifestWork.

type GetValuesFunc

type GetValuesFunc func(cluster *clusterv1.ManagedCluster,
	addon *addonapiv1alpha1.ManagedClusterAddOn) (Values, error)

func GetAddOnDeloymentConfigValues added in v0.5.0

func GetAddOnDeloymentConfigValues(
	getter utils.AddOnDeploymentConfigGetter, toValuesFuncs ...AddOnDeloymentConfigToValuesFunc) GetValuesFunc

GetAddOnDeloymentConfigValues uses AddOnDeloymentConfigGetter to get the AddOnDeploymentConfig object, then uses AddOnDeloymentConfigToValuesFunc to transform the AddOnDeploymentConfig object to Values object If there are multiple AddOnDeploymentConfig objects in the AddOn ConfigReferences, the big index object will override the one from small index Deprecated: use GetAddOnDeploymentConfigValues instead.

func GetAddOnDeploymentConfigValues added in v0.6.1

func GetAddOnDeploymentConfigValues(
	getter utils.AddOnDeploymentConfigGetter, toValuesFuncs ...AddOnDeploymentConfigToValuesFunc) GetValuesFunc

GetAddOnDeploymentConfigValues uses AddOnDeploymentConfigGetter to get the AddOnDeploymentConfig object, then uses AddOnDeploymentConfigToValuesFunc to transform the AddOnDeploymentConfig object to Values object If there are multiple AddOnDeploymentConfig objects in the AddOn ConfigReferences, the big index object will override the one from small index

func GetAgentImageValues added in v0.8.0

func GetAgentImageValues(getter utils.AddOnDeploymentConfigGetter, imageKey, image string) GetValuesFunc

GetAgentImageValues return a func that can use two ways, AddOnDeploymentConfig.spec.Registries and annotation on the ManagedCluster, to override image, then return the overridden value with key imageKey. For example:

  1. configure the image registries with the spec of the AddOnDeploymentConfig, if the registries in the spec is: {...,"spec":{"registries":[{"mirror":"quay.io/ocm/addon-agent","source":"quay.io/open-cluster-management/addon-agent"}]}} the "imageKey" is "helloWorldImage", the "image" is "quay.io/open-cluster-management/addon-agent:v1" after transformed, the Values object will be: {"helloWorldImage": "quay.io/ocm/addon-agent:v1"}

  2. configure the image registries with the annotation "open-cluster-management.io/image-registries" on the ManagedCluster, if the annotation on the managed cluster resource is: "open-cluster-management.io/image-registries": '{"registries":[{"mirror":"quay.io/ocm","source":"quay.io/open-cluster-management"}]}' the "imageKey" is "helloWorldImage", the "image" is "quay.io/open-cluster-management/addon-agent:v1" after transformed, the Values object will be: {"helloWorldImage": "quay.io/ocm/addon-agent:v1"}

Note:

  • the imageKey can support the nested key, for example: "global.imageOverrides.helloWorldImage", the output will be: {"global": {"imageOverrides": {"helloWorldImage": "quay.io/ocm/addon-agent:v1"}}}
  • Image registries configured in the addonDeploymentConfig will take precedence over the managed cluster annotation

type HelmAgentAddon

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

func (*HelmAgentAddon) GetAgentAddonOptions

func (a *HelmAgentAddon) GetAgentAddonOptions() agent.AgentAddonOptions

func (*HelmAgentAddon) Manifests

type TemplateAgentAddon

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

func (*TemplateAgentAddon) GetAgentAddonOptions

func (a *TemplateAgentAddon) GetAgentAddonOptions() agent.AgentAddonOptions

func (*TemplateAgentAddon) Manifests

type Values

type Values map[string]interface{}

func GetValuesFromAddonAnnotation

func GetValuesFromAddonAnnotation(
	cluster *clusterv1.ManagedCluster,
	addon *addonapiv1alpha1.ManagedClusterAddOn) (Values, error)

GetValuesFromAddonAnnotation get the values in the annotation of addon cr. the key of the annotation is `addon.open-cluster-management.io/values`, the value is a json string which has the values. for example: "addon.open-cluster-management.io/values": `{"NodeSelector":{"host":"ssd"},"Image":"quay.io/helloworld:2.4"}`

func JsonStructToValues

func JsonStructToValues(a interface{}) (Values, error)

JsonStructToValues converts the given json struct to a Values

func MergeValues

func MergeValues(a, b Values) Values

MergeValues merges the 2 given Values to a Values. the values of b will override that in a for the same fields.

func StructToValues

func StructToValues(a interface{}) Values

StructToValues converts the given struct to a Values

func ToAddOnCustomizedVariableValues added in v0.6.0

func ToAddOnCustomizedVariableValues(config addonapiv1alpha1.AddOnDeploymentConfig) (Values, error)

ToAddOnCustomizedVariableValues only transform the CustomizedVariables in the spec of AddOnDeploymentConfig into Values object. for example: the spec of one AddOnDeploymentConfig is:

{
 customizedVariables: [{name: "a", value: "x"}, {name: "b", value: "y"}],
}

after transformed, the Values will be: map[a:x b:y]

func ToAddOnDeloymentConfigValues added in v0.5.0

func ToAddOnDeloymentConfigValues(config addonapiv1alpha1.AddOnDeploymentConfig) (Values, error)

ToAddOnDeloymentConfigValues transform the AddOnDeploymentConfig object into Values object that is a plain value map for example: the spec of one AddOnDeploymentConfig is:

{
	customizedVariables: [{name: "Image", value: "img"}, {name: "ImagePullPolicy", value: "Always"}],
	nodePlacement: {nodeSelector: {"host": "ssd"}, tolerations: {"key": "test"}},
}

after transformed, the key set of Values object will be: {"Image", "ImagePullPolicy", "NodeSelector", "Tolerations"} Deprecated: use ToAddOnDeploymentConfigValues instead.

func ToAddOnDeploymentConfigValues added in v0.6.1

func ToAddOnDeploymentConfigValues(config addonapiv1alpha1.AddOnDeploymentConfig) (Values, error)

ToAddOnDeploymentConfigValues transform the AddOnDeploymentConfig object into Values object that is a plain value map for example: the spec of one AddOnDeploymentConfig is:

{
	customizedVariables: [{name: "Image", value: "img"}, {name: "ImagePullPolicy", value: "Always"}],
	nodePlacement: {nodeSelector: {"host": "ssd"}, tolerations: {"key": "test"}},
}

after transformed, the key set of Values object will be: {"Image", "ImagePullPolicy", "NodeSelector", "Tolerations"}

func ToAddOnNodePlacementValues added in v0.5.0

func ToAddOnNodePlacementValues(config addonapiv1alpha1.AddOnDeploymentConfig) (Values, error)

ToAddOnNodePlacementValues only transform the AddOnDeploymentConfig NodePlacement part into Values object that has a specific for helm chart values for example: the spec of one AddOnDeploymentConfig is:

{
 nodePlacement: {nodeSelector: {"host": "ssd"}, tolerations: {"key":"test"}},
}

after transformed, the Values will be: map[global:map[nodeSelector:map[host:ssd]] tolerations:[map[key:test]]]

func ToAddOnProxyConfigValues added in v0.8.0

func ToAddOnProxyConfigValues(config addonapiv1alpha1.AddOnDeploymentConfig) (Values, error)

ToAddOnProxyConfigValues transform the spec.proxyConfig of AddOnDeploymentConfig into Values object that has a specific for helm chart values for example: the spec of one AddOnDeploymentConfig is:

{
 proxyConfig: {"httpProxy": "http://10.11.12.13:3128", "httpsProxy": "https://10.11.12.13:3129", "noProxy": "example.com"},
}

after transformed, the Values will be: map[global:map[proxyConfig:map[httpProxy:http://10.11.12.13:3128 httpsProxy:https://10.11.12.13:3129 noProxy:example.com]]]

Jump to

Keyboard shortcuts

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