diff --git a/api/v1alpha2/provider_types.go b/api/v1alpha2/provider_types.go index c4a9955b..119cd8cc 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 41790a86..fad2dae7 100644 --- a/internal/controller/manifests_downloader.go +++ b/internal/controller/manifests_downloader.go @@ -45,12 +45,6 @@ const ( configMapSourceLabel = "provider.cluster.x-k8s.io/source" 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 ociSource = "oci" ) @@ -173,13 +167,13 @@ func TemplateManifestsConfigMap(provider operatorv1.GenericProvider, labels map[ Labels: labels, }, 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) @@ -194,11 +188,11 @@ func TemplateManifestsConfigMap(provider operatorv1.GenericProvider, labels map[ } 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 := provider.GetObjectKind().GroupVersionKind() diff --git a/internal/controller/phases.go b/internal/controller/phases.go index e8f5800b..b52834a2 100644 --- a/internal/controller/phases.go +++ b/internal/controller/phases.go @@ -322,7 +322,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) } @@ -355,14 +355,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) } @@ -371,7 +371,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) }