Skip to content

Commit 36c2c84

Browse files
authored
Merge pull request #687 from dmvolod/make-metadata-and-component-keys-exportable
🌱 Make annotation and component constants public and exportable
2 parents 911b5c5 + 490de73 commit 36c2c84

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

api/v1alpha2/provider_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import (
2525
const (
2626
ProviderFinalizer = "provider.cluster.x-k8s.io"
2727
ConfigMapVersionLabelName = "provider.cluster.x-k8s.io/version"
28+
29+
CompressedAnnotation = "provider.cluster.x-k8s.io/compressed"
30+
31+
MetadataConfigMapKey = "metadata"
32+
ComponentsConfigMapKey = "components"
33+
AdditionalManifestsConfigMapKey = "manifests"
2834
)
2935

3036
// ProviderSpec is the desired state of the Provider.

internal/controller/manifests_downloader.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ const (
4545
configMapSourceLabel = "provider.cluster.x-k8s.io/source"
4646
operatorManagedLabel = "managed-by.operator.cluster.x-k8s.io"
4747

48-
compressedAnnotation = "provider.cluster.x-k8s.io/compressed"
49-
50-
metadataConfigMapKey = "metadata"
51-
componentsConfigMapKey = "components"
52-
additionalManifestsConfigMapKey = "manifests"
53-
5448
maxConfigMapSize = 1 * 1024 * 1024
5549
ociSource = "oci"
5650
)
@@ -173,13 +167,13 @@ func TemplateManifestsConfigMap(provider operatorv1.GenericProvider, labels map[
173167
Labels: labels,
174168
},
175169
Data: map[string]string{
176-
metadataConfigMapKey: string(metadata),
170+
operatorv1.MetadataConfigMapKey: string(metadata),
177171
},
178172
}
179173

180174
// Components manifests data can exceed the configmap size limit. In this case we have to compress it.
181175
if !compress {
182-
configMap.Data[componentsConfigMapKey] = string(components)
176+
configMap.Data[operatorv1.ComponentsConfigMapKey] = string(components)
183177
} else {
184178
var componentsBuf bytes.Buffer
185179
zw := gzip.NewWriter(&componentsBuf)
@@ -194,11 +188,11 @@ func TemplateManifestsConfigMap(provider operatorv1.GenericProvider, labels map[
194188
}
195189

196190
configMap.BinaryData = map[string][]byte{
197-
componentsConfigMapKey: componentsBuf.Bytes(),
191+
operatorv1.ComponentsConfigMapKey: componentsBuf.Bytes(),
198192
}
199193

200194
// Setting the annotation to mark these manifests as compressed.
201-
configMap.SetAnnotations(map[string]string{compressedAnnotation: "true"})
195+
configMap.SetAnnotations(map[string]string{operatorv1.CompressedAnnotation: "true"})
202196
}
203197

204198
gvk := provider.GetObjectKind().GroupVersionKind()

internal/controller/phases.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func (p *phaseReconciler) configmapRepository(ctx context.Context, labelSelector
322322
return nil, fmt.Errorf("ConfigMap %s/%s has invalid version:%s (%s)", cm.Namespace, cm.Name, version, errMsg)
323323
}
324324

325-
metadata, ok := cm.Data[metadataConfigMapKey]
325+
metadata, ok := cm.Data[operatorv1.MetadataConfigMapKey]
326326
if !ok {
327327
return nil, fmt.Errorf("ConfigMap %s/%s has no metadata", cm.Namespace, cm.Name)
328328
}
@@ -355,14 +355,14 @@ func (p *phaseReconciler) fetchAddionalManifests(ctx context.Context) (string, e
355355
}
356356
}
357357

358-
return cm.Data[additionalManifestsConfigMapKey], nil
358+
return cm.Data[operatorv1.AdditionalManifestsConfigMapKey], nil
359359
}
360360

361361
// getComponentsData returns components data based on if it's compressed or not.
362362
func getComponentsData(cm corev1.ConfigMap) (string, error) {
363363
// Data is not compressed, return it immediately.
364-
if cm.GetAnnotations()[compressedAnnotation] != "true" {
365-
components, ok := cm.Data[componentsConfigMapKey]
364+
if cm.GetAnnotations()[operatorv1.CompressedAnnotation] != "true" {
365+
components, ok := cm.Data[operatorv1.ComponentsConfigMapKey]
366366
if !ok {
367367
return "", fmt.Errorf("ConfigMap %s/%s Data has no components", cm.Namespace, cm.Name)
368368
}
@@ -371,7 +371,7 @@ func getComponentsData(cm corev1.ConfigMap) (string, error) {
371371
}
372372

373373
// Otherwise we have to decompress the data first.
374-
compressedComponents, ok := cm.BinaryData[componentsConfigMapKey]
374+
compressedComponents, ok := cm.BinaryData[operatorv1.ComponentsConfigMapKey]
375375
if !ok {
376376
return "", fmt.Errorf("ConfigMap %s/%s BinaryData has no components", cm.Namespace, cm.Name)
377377
}

0 commit comments

Comments
 (0)