Skip to content

Commit

Permalink
🌱 Make annotation and component constants public and exportable
Browse files Browse the repository at this point in the history
  • Loading branch information
dmvolod committed Jan 23, 2025
1 parent 4dab0b7 commit 490de73
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha2/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 4 additions & 10 deletions internal/controller/manifests_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 490de73

Please sign in to comment.