Skip to content

Commit 490de73

Browse files
committed
🌱 Make annotation and component constants public and exportable
1 parent 4dab0b7 commit 490de73

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
@@ -41,12 +41,6 @@ const (
4141
configMapNameLabel = "provider.cluster.x-k8s.io/name"
4242
operatorManagedLabel = "managed-by.operator.cluster.x-k8s.io"
4343

44-
compressedAnnotation = "provider.cluster.x-k8s.io/compressed"
45-
46-
metadataConfigMapKey = "metadata"
47-
componentsConfigMapKey = "components"
48-
additionalManifestsConfigMapKey = "manifests"
49-
5044
maxConfigMapSize = 1 * 1024 * 1024
5145
)
5246

@@ -159,13 +153,13 @@ func (p *phaseReconciler) createManifestsConfigMap(ctx context.Context, metadata
159153
Labels: p.prepareConfigMapLabels(),
160154
},
161155
Data: map[string]string{
162-
metadataConfigMapKey: string(metadata),
156+
operatorv1.MetadataConfigMapKey: string(metadata),
163157
},
164158
}
165159

166160
// Components manifests data can exceed the configmap size limit. In this case we have to compress it.
167161
if !compress {
168-
configMap.Data[componentsConfigMapKey] = string(components)
162+
configMap.Data[operatorv1.ComponentsConfigMapKey] = string(components)
169163
} else {
170164
var componentsBuf bytes.Buffer
171165
zw := gzip.NewWriter(&componentsBuf)
@@ -180,11 +174,11 @@ func (p *phaseReconciler) createManifestsConfigMap(ctx context.Context, metadata
180174
}
181175

182176
configMap.BinaryData = map[string][]byte{
183-
componentsConfigMapKey: componentsBuf.Bytes(),
177+
operatorv1.ComponentsConfigMapKey: componentsBuf.Bytes(),
184178
}
185179

186180
// Setting the annotation to mark these manifests as compressed.
187-
configMap.SetAnnotations(map[string]string{compressedAnnotation: "true"})
181+
configMap.SetAnnotations(map[string]string{operatorv1.CompressedAnnotation: "true"})
188182
}
189183

190184
gvk := p.provider.GetObjectKind().GroupVersionKind()

internal/controller/phases.go

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

319-
metadata, ok := cm.Data[metadataConfigMapKey]
319+
metadata, ok := cm.Data[operatorv1.MetadataConfigMapKey]
320320
if !ok {
321321
return nil, fmt.Errorf("ConfigMap %s/%s has no metadata", cm.Namespace, cm.Name)
322322
}
@@ -349,14 +349,14 @@ func (p *phaseReconciler) fetchAddionalManifests(ctx context.Context) (string, e
349349
}
350350
}
351351

352-
return cm.Data[additionalManifestsConfigMapKey], nil
352+
return cm.Data[operatorv1.AdditionalManifestsConfigMapKey], nil
353353
}
354354

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

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

0 commit comments

Comments
 (0)