From 490de736ac89b34addfed0c37a7b33c48fd764cb Mon Sep 17 00:00:00 2001 From: Dmitry Volodin Date: Thu, 23 Jan 2025 21:56:13 +0300 Subject: [PATCH] :seedling: Make annotation and component constants public and exportable --- api/v1alpha2/provider_types.go | 6 ++++++ internal/controller/manifests_downloader.go | 14 ++++---------- internal/controller/phases.go | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/api/v1alpha2/provider_types.go b/api/v1alpha2/provider_types.go index 4fb8c53eb..221749de3 100644 --- a/api/v1alpha2/provider_types.go +++ b/api/v1alpha2/provider_types.go @@ -25,6 +25,12 @@ import ( const ( ProviderFinalizer = "provider.cluster.x-k8s.io" ConfigMapVersionLabelName = "provider.cluster.x-k8s.io/version" + + CompressedAnnotation = "provider.cluster.x-k8s.io/compressed" + + MetadataConfigMapKey = "metadata" + ComponentsConfigMapKey = "components" + AdditionalManifestsConfigMapKey = "manifests" ) // ProviderSpec is the desired state of the Provider. diff --git a/internal/controller/manifests_downloader.go b/internal/controller/manifests_downloader.go index dc29d190e..d39a39a72 100644 --- a/internal/controller/manifests_downloader.go +++ b/internal/controller/manifests_downloader.go @@ -41,12 +41,6 @@ const ( configMapNameLabel = "provider.cluster.x-k8s.io/name" operatorManagedLabel = "managed-by.operator.cluster.x-k8s.io" - compressedAnnotation = "provider.cluster.x-k8s.io/compressed" - - metadataConfigMapKey = "metadata" - componentsConfigMapKey = "components" - additionalManifestsConfigMapKey = "manifests" - maxConfigMapSize = 1 * 1024 * 1024 ) @@ -159,13 +153,13 @@ func (p *phaseReconciler) createManifestsConfigMap(ctx context.Context, metadata Labels: p.prepareConfigMapLabels(), }, Data: map[string]string{ - metadataConfigMapKey: string(metadata), + operatorv1.MetadataConfigMapKey: string(metadata), }, } // Components manifests data can exceed the configmap size limit. In this case we have to compress it. if !compress { - configMap.Data[componentsConfigMapKey] = string(components) + configMap.Data[operatorv1.ComponentsConfigMapKey] = string(components) } else { var componentsBuf bytes.Buffer zw := gzip.NewWriter(&componentsBuf) @@ -180,11 +174,11 @@ func (p *phaseReconciler) createManifestsConfigMap(ctx context.Context, metadata } configMap.BinaryData = map[string][]byte{ - componentsConfigMapKey: componentsBuf.Bytes(), + operatorv1.ComponentsConfigMapKey: componentsBuf.Bytes(), } // Setting the annotation to mark these manifests as compressed. - configMap.SetAnnotations(map[string]string{compressedAnnotation: "true"}) + configMap.SetAnnotations(map[string]string{operatorv1.CompressedAnnotation: "true"}) } gvk := p.provider.GetObjectKind().GroupVersionKind() diff --git a/internal/controller/phases.go b/internal/controller/phases.go index b20e61ac3..d26b71745 100644 --- a/internal/controller/phases.go +++ b/internal/controller/phases.go @@ -316,7 +316,7 @@ func (p *phaseReconciler) configmapRepository(ctx context.Context, labelSelector return nil, fmt.Errorf("ConfigMap %s/%s has invalid version:%s (%s)", cm.Namespace, cm.Name, version, errMsg) } - metadata, ok := cm.Data[metadataConfigMapKey] + metadata, ok := cm.Data[operatorv1.MetadataConfigMapKey] if !ok { return nil, fmt.Errorf("ConfigMap %s/%s has no metadata", cm.Namespace, cm.Name) } @@ -349,14 +349,14 @@ func (p *phaseReconciler) fetchAddionalManifests(ctx context.Context) (string, e } } - return cm.Data[additionalManifestsConfigMapKey], nil + return cm.Data[operatorv1.AdditionalManifestsConfigMapKey], nil } // getComponentsData returns components data based on if it's compressed or not. func getComponentsData(cm corev1.ConfigMap) (string, error) { // Data is not compressed, return it immediately. - if cm.GetAnnotations()[compressedAnnotation] != "true" { - components, ok := cm.Data[componentsConfigMapKey] + if cm.GetAnnotations()[operatorv1.CompressedAnnotation] != "true" { + components, ok := cm.Data[operatorv1.ComponentsConfigMapKey] if !ok { return "", fmt.Errorf("ConfigMap %s/%s Data has no components", cm.Namespace, cm.Name) } @@ -365,7 +365,7 @@ func getComponentsData(cm corev1.ConfigMap) (string, error) { } // Otherwise we have to decompress the data first. - compressedComponents, ok := cm.BinaryData[componentsConfigMapKey] + compressedComponents, ok := cm.BinaryData[operatorv1.ComponentsConfigMapKey] if !ok { return "", fmt.Errorf("ConfigMap %s/%s BinaryData has no components", cm.Namespace, cm.Name) }