resourceapply

package
v0.0.0-...-5152f1c Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CredentialsRequestGroup    = "cloudcredential.openshift.io"
	CredentialsRequestVersion  = "v1"
	CredentialsRequestResource = "credentialsrequests"
)
View Source
const (
	VolumeSnapshotClassGroup    = "snapshot.storage.k8s.io"
	VolumeSnapshotClassVersion  = "v1"
	VolumeSnapshotClassResource = "volumesnapshotclasses"
)

Variables

This section is empty.

Functions

func AddCredentialsRequestHash

func AddCredentialsRequestHash(cr *unstructured.Unstructured) error

func ApplyAPIService

ApplyAPIService merges objectmeta and requires apiservice coordinates. It does not touch CA bundles, which should be managed via service CA controller.

func ApplyAlertmanager

func ApplyAlertmanager(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

ApplyAlertmanager applies the Alertmanager.

func ApplyCSIDriver

func ApplyCSIDriver(ctx context.Context, client storageclientv1.CSIDriversGetter, recorder events.Recorder, requiredOriginal *storagev1.CSIDriver) (*storagev1.CSIDriver, bool, error)

ApplyCSIDriver merges objectmeta, does not worry about anything else

func ApplyClusterRole

func ApplyClusterRole(ctx context.Context, client rbacclientv1.ClusterRolesGetter, recorder events.Recorder, required *rbacv1.ClusterRole) (*rbacv1.ClusterRole, bool, error)

ApplyClusterRole merges objectmeta, requires rules.

func ApplyClusterRoleBinding

ApplyClusterRoleBinding merges objectmeta, requires subjects and role refs TODO on non-matching roleref, delete and recreate

func ApplyConfigMap

func ApplyConfigMap(ctx context.Context, client coreclientv1.ConfigMapsGetter, recorder events.Recorder, required *corev1.ConfigMap) (*corev1.ConfigMap, bool, error)

ApplyConfigMap merges objectmeta, requires data

func ApplyConfigMapImproved

func ApplyConfigMapImproved(ctx context.Context, client coreclientv1.ConfigMapsGetter, recorder events.Recorder, required *corev1.ConfigMap, cache ResourceCache) (*corev1.ConfigMap, bool, error)

ApplyConfigMap merges objectmeta, requires data

func ApplyCredentialsRequest

func ApplyCredentialsRequest(
	ctx context.Context,
	client dynamic.Interface,
	recorder events.Recorder,
	required *unstructured.Unstructured,
	expectedGeneration int64,
) (*unstructured.Unstructured, bool, error)

func ApplyCustomResourceDefinitionV1

ApplyCustomResourceDefinitionV1 applies the required CustomResourceDefinition to the cluster.

func ApplyDaemonSet

func ApplyDaemonSet(ctx context.Context, client appsclientv1.DaemonSetsGetter, recorder events.Recorder,
	requiredOriginal *appsv1.DaemonSet, expectedGeneration int64) (*appsv1.DaemonSet, bool, error)

ApplyDaemonSet ensures the form of the specified daemonset is present in the API. If it does not exist, it will be created. If it does exist, the metadata of the required daemonset will be merged with the existing daemonset and an update performed if the daemonset spec and metadata differ from the previously required spec and metadata. For further detail, check the top-level comment.

NOTE: The previous implementation of this method was renamed to ApplyDaemonSetWithForce. If are reading this in response to a compile error due to the change in signature, you have the following options:

- Update the calling code to rely on the spec comparison provided by the new implementation. If the code in question was specifying the force parameter to ensure rollout in response to changes in resources external to the daemonset, it will need to be revised to set that external state as an annotation e.g.

myoperator.openshift.io/my-resource: <resourceVersion>

- Update the call to use ApplyDaemonSetWithForce. This is available as a temporary measure but the method is deprecated and will be removed in 4.6.

func ApplyDaemonSetWithForce

func ApplyDaemonSetWithForce(ctx context.Context, client appsclientv1.DaemonSetsGetter, recorder events.Recorder, requiredOriginal *appsv1.DaemonSet, expectedGeneration int64, forceRollout bool) (*appsv1.DaemonSet, bool, error)

ApplyDaemonSetWithForce merges objectmeta and requires matching generation. It returns the final Object, whether any change as made, and an error DEPRECATED - This method will be removed in 4.6 and callers will need to migrate to ApplyDaemonSet before then.

func ApplyDeployment

func ApplyDeployment(ctx context.Context, client appsclientv1.DeploymentsGetter, recorder events.Recorder,
	requiredOriginal *appsv1.Deployment, expectedGeneration int64) (*appsv1.Deployment, bool, error)

ApplyDeployment ensures the form of the specified deployment is present in the API. If it does not exist, it will be created. If it does exist, the metadata of the required deployment will be merged with the existing deployment and an update performed if the deployment spec and metadata differ from the previously required spec and metadata. For further detail, check the top-level comment.

NOTE: The previous implementation of this method was renamed to ApplyDeploymentWithForce. If are reading this in response to a compile error due to the change in signature, you have the following options:

- Update the calling code to rely on the spec comparison provided by the new implementation. If the code in question was specifying the force parameter to ensure rollout in response to changes in resources external to the deployment, it will need to be revised to set that external state as an annotation e.g.

myoperator.openshift.io/my-resource: <resourceVersion>

- Update the call to use ApplyDeploymentWithForce. This is available as a temporary measure but the method is deprecated and will be removed in 4.6.

func ApplyDeploymentWithForce

func ApplyDeploymentWithForce(ctx context.Context, client appsclientv1.DeploymentsGetter, recorder events.Recorder, requiredOriginal *appsv1.Deployment, expectedGeneration int64,
	forceRollout bool) (*appsv1.Deployment, bool, error)

ApplyDeploymentWithForce merges objectmeta and requires matching generation. It returns the final Object, whether any change as made, and an error.

DEPRECATED - This method will be removed in 4.6 and callers will need to migrate to ApplyDeployment before then.

func ApplyKnownUnstructured

func ApplyKnownUnstructured(ctx context.Context, client dynamic.Interface, recorder events.Recorder, obj *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

ApplyKnownUnstructured applies few selected Unstructured types, where it semantic knowledge to merge existing & required objects intelligently. Feel free to add more.

func ApplyMutatingWebhookConfigurationImproved

ApplyMutatingWebhookConfigurationImproved ensures the form of the specified mutatingwebhookconfiguration is present in the API. If it does not exist, it will be created. If it does exist, the metadata of the required mutatingwebhookconfiguration will be merged with the existing mutatingwebhookconfiguration and an update performed if the mutatingwebhookconfiguration spec and metadata differ from the previously required spec and metadata based on generation change.

func ApplyNamespace

func ApplyNamespace(ctx context.Context, client coreclientv1.NamespacesGetter, recorder events.Recorder, required *corev1.Namespace) (*corev1.Namespace, bool, error)

ApplyNamespace merges objectmeta, does not worry about anything else

func ApplyNamespaceImproved

func ApplyNamespaceImproved(ctx context.Context, client coreclientv1.NamespacesGetter, recorder events.Recorder, required *corev1.Namespace, cache ResourceCache) (*corev1.Namespace, bool, error)

ApplyNamespace merges objectmeta, does not worry about anything else

func ApplyPod

func ApplyPod(ctx context.Context, client coreclientv1.PodsGetter, recorder events.Recorder, required *corev1.Pod) (*corev1.Pod, bool, error)

ApplyPod merges objectmeta, does not worry about anything else

func ApplyPodImproved

func ApplyPodImproved(ctx context.Context, client coreclientv1.PodsGetter, recorder events.Recorder, required *corev1.Pod, cache ResourceCache) (*corev1.Pod, bool, error)

ApplyPod merges objectmeta, does not worry about anything else

func ApplyPrometheus

func ApplyPrometheus(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

ApplyPrometheus applies the Prometheus.

func ApplyPrometheusRule

func ApplyPrometheusRule(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

ApplyPrometheusRule applies the PrometheusRule.

func ApplyRole

func ApplyRole(ctx context.Context, client rbacclientv1.RolesGetter, recorder events.Recorder, required *rbacv1.Role) (*rbacv1.Role, bool, error)

ApplyRole merges objectmeta, requires rules

func ApplyRoleBinding

func ApplyRoleBinding(ctx context.Context, client rbacclientv1.RoleBindingsGetter, recorder events.Recorder, required *rbacv1.RoleBinding) (*rbacv1.RoleBinding, bool, error)

ApplyRoleBinding merges objectmeta, requires subjects and role refs TODO on non-matching roleref, delete and recreate

func ApplySecret

func ApplySecret(ctx context.Context, client coreclientv1.SecretsGetter, recorder events.Recorder, required *corev1.Secret) (*corev1.Secret, bool, error)

ApplySecret merges objectmeta, requires data

func ApplySecretImproved

func ApplySecretImproved(ctx context.Context, client coreclientv1.SecretsGetter, recorder events.Recorder, requiredInput *corev1.Secret, cache ResourceCache) (*corev1.Secret, bool, error)

ApplySecret merges objectmeta, requires data

func ApplyService

func ApplyService(ctx context.Context, client coreclientv1.ServicesGetter, recorder events.Recorder, required *corev1.Service) (*corev1.Service, bool, error)

ApplyService merges objectmeta and requires TODO, since this cannot determine whether changes are due to legitimate actors (api server) or illegitimate ones (users), we cannot update TODO I've special cased the selector for now

func ApplyServiceAccount

func ApplyServiceAccount(ctx context.Context, client coreclientv1.ServiceAccountsGetter, recorder events.Recorder, required *corev1.ServiceAccount) (*corev1.ServiceAccount, bool, error)

ApplyServiceAccount merges objectmeta, does not worry about anything else

func ApplyServiceAccountImproved

func ApplyServiceAccountImproved(ctx context.Context, client coreclientv1.ServiceAccountsGetter, recorder events.Recorder, required *corev1.ServiceAccount, cache ResourceCache) (*corev1.ServiceAccount, bool, error)

ApplyServiceAccount merges objectmeta, does not worry about anything else

func ApplyServiceImproved

func ApplyServiceImproved(ctx context.Context, client coreclientv1.ServicesGetter, recorder events.Recorder, requiredOriginal *corev1.Service, cache ResourceCache) (*corev1.Service, bool, error)

ApplyService merges objectmeta and requires. It detects changes in `required`, i.e. an operator needs .spec changes and overwrites existing .spec with those. TODO, since this cannot determine whether changes in `existing` are due to legitimate actors (api server) or illegitimate ones (users), we cannot update. TODO I've special cased the selector for now

func ApplyServiceMonitor

func ApplyServiceMonitor(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

ApplyServiceMonitor applies the ServiceMonitor.

func ApplyStorageClass

ApplyStorageClass merges objectmeta, tries to write everything else

func ApplyStorageVersionMigration

ApplyStorageVersionMigration merges objectmeta and required data.

func ApplyUnstructuredResourceImproved

func ApplyUnstructuredResourceImproved(
	ctx context.Context,
	client dynamic.Interface,
	recorder events.Recorder,
	required *unstructured.Unstructured,
	cache ResourceCache,
	resourceGVR schema.GroupVersionResource,
	defaultingFunc mimicDefaultingFunc,
	equalityChecker equalityChecker,
) (*unstructured.Unstructured, bool, error)

ApplyUnstructuredResourceImproved can utilize the cache to reconcile the existing resource to the desired state. NOTE: A `nil` defaultingFunc and equalityChecker are assigned resourceapply.noDefaulting and equality.Semantic, respectively. Users are recommended to instantiate a cache to benefit from the memoization machinery.

func ApplyValidatingAdmissionPolicyBindingV1

ApplyValidatingAdmissionPolicyBindingV1 ensures the form of the specified validatingadmissionpolicybindingconfiguration is present in the API. If it does not exist, it will be created. If it does exist, the metadata of the required validatingadmissionpolicybindingconfiguration will be merged with the existing validatingadmissionpolicybindingconfiguration and an update performed if the validatingadmissionpolicybindingconfiguration spec and metadata differ from the previously required spec and metadata based on generation change.

func ApplyValidatingAdmissionPolicyBindingV1beta1

ApplyValidatingAdmissionPolicyBindingV1beta1 ensures the form of the specified validatingadmissionpolicybindingconfiguration is present in the API. If it does not exist, it will be created. If it does exist, the metadata of the required validatingadmissionpolicybindingconfiguration will be merged with the existing validatingadmissionpolicybindingconfiguration and an update performed if the validatingadmissionpolicybindingconfiguration spec and metadata differ from the previously required spec and metadata based on generation change.

func ApplyValidatingAdmissionPolicyV1

ApplyValidatingAdmissionPolicyV1 ensures the form of the specified validatingadmissionpolicyconfiguration is present in the API. If it does not exist, it will be created. If it does exist, the metadata of the required validatingadmissionpolicyconfiguration will be merged with the existing validatingadmissionpolicyconfiguration and an update performed if the validatingadmissionpolicyconfiguration spec and metadata differ from the previously required spec and metadata based on generation change.

func ApplyValidatingAdmissionPolicyV1beta1

ApplyValidatingAdmissionPolicyV1beta1 ensures the form of the specified validatingadmissionpolicyconfiguration is present in the API. If it does not exist, it will be created. If it does exist, the metadata of the required validatingadmissionpolicyconfiguration will be merged with the existing validatingadmissionpolicyconfiguration and an update performed if the validatingadmissionpolicyconfiguration spec and metadata differ from the previously required spec and metadata based on generation change.

func ApplyValidatingWebhookConfigurationImproved

ApplyValidatingWebhookConfigurationImproved ensures the form of the specified validatingwebhookconfiguration is present in the API. If it does not exist, it will be created. If it does exist, the metadata of the required validatingwebhookconfiguration will be merged with the existing validatingwebhookconfiguration and an update performed if the validatingwebhookconfiguration spec and metadata differ from the previously required spec and metadata based on generation change.

func ApplyVolumeSnapshotClass

func ApplyVolumeSnapshotClass(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

ApplyVolumeSnapshotClass applies Volume Snapshot Class.

func DeleteAlertmanager

func DeleteAlertmanager(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

DeleteAlertmanager deletes the Alertmanager.

func DeleteClusterRole

func DeleteClusterRole(ctx context.Context, client rbacclientv1.ClusterRolesGetter, recorder events.Recorder, required *rbacv1.ClusterRole) (*rbacv1.ClusterRole, bool, error)

func DeleteConfigMap

func DeleteConfigMap(ctx context.Context, client coreclientv1.ConfigMapsGetter, recorder events.Recorder, required *corev1.ConfigMap) (*corev1.ConfigMap, bool, error)

func DeleteDaemonSet

func DeleteDaemonSet(ctx context.Context, client appsclientv1.DaemonSetsGetter, recorder events.Recorder, required *appsv1.DaemonSet) (*appsv1.DaemonSet, bool, error)

func DeleteDeployment

func DeleteDeployment(ctx context.Context, client appsclientv1.DeploymentsGetter, recorder events.Recorder, required *appsv1.Deployment) (*appsv1.Deployment, bool, error)

func DeleteKnownUnstructured

func DeleteKnownUnstructured(ctx context.Context, client dynamic.Interface, recorder events.Recorder, obj *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

DeleteKnownUnstructured deletes few selected Unstructured types

func DeleteNamespace

func DeleteNamespace(ctx context.Context, client coreclientv1.NamespacesGetter, recorder events.Recorder, required *corev1.Namespace) (*corev1.Namespace, bool, error)

func DeletePod

func DeletePod(ctx context.Context, client coreclientv1.PodsGetter, recorder events.Recorder, required *corev1.Pod) (*corev1.Pod, bool, error)

func DeletePrometheus

func DeletePrometheus(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

DeletePrometheus deletes the Prometheus.

func DeletePrometheusRule

func DeletePrometheusRule(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

DeletePrometheusRule deletes the PrometheusRule.

func DeleteRole

func DeleteRole(ctx context.Context, client rbacclientv1.RolesGetter, recorder events.Recorder, required *rbacv1.Role) (*rbacv1.Role, bool, error)

func DeleteRoleBinding

func DeleteRoleBinding(ctx context.Context, client rbacclientv1.RoleBindingsGetter, recorder events.Recorder, required *rbacv1.RoleBinding) (*rbacv1.RoleBinding, bool, error)

func DeleteSecret

func DeleteSecret(ctx context.Context, client coreclientv1.SecretsGetter, recorder events.Recorder, required *corev1.Secret) (*corev1.Secret, bool, error)

func DeleteService

func DeleteService(ctx context.Context, client coreclientv1.ServicesGetter, recorder events.Recorder, required *corev1.Service) (*corev1.Service, bool, error)

func DeleteServiceMonitor

func DeleteServiceMonitor(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

DeleteServiceMonitor deletes the ServiceMonitor.

func DeleteUnstructuredResource

func DeleteUnstructuredResource(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured, resourceGVR schema.GroupVersionResource) (*unstructured.Unstructured, bool, error)

DeleteUnstructuredResource deletes the unstructured resource.

func DeleteVolumeSnapshotClass

func DeleteVolumeSnapshotClass(ctx context.Context, client dynamic.Interface, recorder events.Recorder, required *unstructured.Unstructured) (*unstructured.Unstructured, bool, error)

func JSONPatchNoError

func JSONPatchNoError(original, modified runtime.Object) string

JSONPatchNoError generates a JSON patch between original and modified objects and return the JSON as a string. Note:

In case of error, the returned string will contain the error messages.

func JSONPatchSecretNoError

func JSONPatchSecretNoError(original, modified *corev1.Secret) string

JSONPatchSecretNoError generates a JSON patch between original and modified secrets, hiding its data, and return the JSON as a string.

Note: In case of error, the returned string will contain the error messages.

func NewResourceCache

func NewResourceCache() *resourceCache

func SetSpecHashAnnotation

func SetSpecHashAnnotation(objMeta *metav1.ObjectMeta, spec interface{}) error

SetSpecHashAnnotation computes the hash of the provided spec and sets an annotation of the hash on the provided ObjectMeta. This method is used internally by Apply<type> methods, and is exposed to support testing with fake clients that need to know the mutated form of the resource resulting from an Apply<type> call.

func SyncConfigMap

func SyncConfigMap(ctx context.Context, client coreclientv1.ConfigMapsGetter, recorder events.Recorder, sourceNamespace, sourceName, targetNamespace, targetName string, ownerRefs []metav1.OwnerReference) (*corev1.ConfigMap, bool, error)

SyncConfigMap applies a ConfigMap from a location `sourceNamespace/sourceName` to `targetNamespace/targetName`

func SyncPartialConfigMap

func SyncPartialConfigMap(ctx context.Context, client coreclientv1.ConfigMapsGetter, recorder events.Recorder, sourceNamespace, sourceName, targetNamespace, targetName string, syncedKeys sets.Set[string], ownerRefs []metav1.OwnerReference) (*corev1.ConfigMap, bool, error)

SyncPartialConfigMap does what SyncConfigMap does but it only synchronizes a subset of keys given by `syncedKeys`. SyncPartialConfigMap will delete the target if `syncedKeys` are set but the source does not contain any of these keys.

func SyncPartialSecret

func SyncPartialSecret(ctx context.Context, client coreclientv1.SecretsGetter, recorder events.Recorder, sourceNamespace, sourceName, targetNamespace, targetName string, syncedKeys sets.Set[string], ownerRefs []metav1.OwnerReference) (*corev1.Secret, bool, error)

SyncPartialSecret does what SyncSecret does but it only synchronizes a subset of keys given by `syncedKeys`. SyncPartialSecret will delete the target if `syncedKeys` are set but the source does not contain any of these keys.

func SyncSecret

func SyncSecret(ctx context.Context, client coreclientv1.SecretsGetter, recorder events.Recorder, sourceNamespace, sourceName, targetNamespace, targetName string, ownerRefs []metav1.OwnerReference) (*corev1.Secret, bool, error)

SyncSecret applies a Secret from a location `sourceNamespace/sourceName` to `targetNamespace/targetName`

Types

type ApplyResult

type ApplyResult struct {
	File    string
	Type    string
	Result  runtime.Object
	Changed bool
	Error   error
}

func ApplyDirectly

func ApplyDirectly(ctx context.Context, clients *ClientHolder, recorder events.Recorder, cache ResourceCache, manifests AssetFunc, files ...string) []ApplyResult

ApplyDirectly applies the given manifest files to API server.

func DeleteAll

func DeleteAll(ctx context.Context, clients *ClientHolder, recorder events.Recorder, manifests AssetFunc,
	files ...string) []ApplyResult

type AssetFunc

type AssetFunc func(name string) ([]byte, error)

type ClientHolder

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

func NewClientHolder

func NewClientHolder() *ClientHolder

func NewKubeClientHolder

func NewKubeClientHolder(client kubernetes.Interface) *ClientHolder

func (*ClientHolder) WithAPIExtensionsClient

func (c *ClientHolder) WithAPIExtensionsClient(client apiextensionsclient.Interface) *ClientHolder

func (*ClientHolder) WithDynamicClient

func (c *ClientHolder) WithDynamicClient(client dynamic.Interface) *ClientHolder

func (*ClientHolder) WithKubernetes

func (c *ClientHolder) WithKubernetes(client kubernetes.Interface) *ClientHolder

func (*ClientHolder) WithKubernetesInformers

func (c *ClientHolder) WithKubernetesInformers(kubeInformers v1helpers.KubeInformersForNamespaces) *ClientHolder

func (*ClientHolder) WithMigrationClient

func (c *ClientHolder) WithMigrationClient(client migrationclient.Interface) *ClientHolder

type ConditionalFunction

type ConditionalFunction func() bool

ConditionalFunction provides needed dependency for a resource on another condition instead of blindly creating a resource. This conditional function can also be used to delete the resource when not needed

type ResourceCache

type ResourceCache interface {
	UpdateCachedResourceMetadata(required runtime.Object, actual runtime.Object)
	SafeToSkipApply(required runtime.Object, existing runtime.Object) bool
}

Jump to

Keyboard shortcuts

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