|
| 1 | +suite: test config-loader job labels and annotations |
| 2 | +templates: |
| 3 | + - templates/config-loader-job.yaml |
| 4 | +tests: |
| 5 | + # Test default labels are applied |
| 6 | + - it: should apply default labels to Job metadata |
| 7 | + set: |
| 8 | + defaults.labels: |
| 9 | + custom-label: "default-value" |
| 10 | + team: "platform" |
| 11 | + asserts: |
| 12 | + - equal: |
| 13 | + path: metadata.labels["custom-label"] |
| 14 | + value: "default-value" |
| 15 | + - equal: |
| 16 | + path: metadata.labels["team"] |
| 17 | + value: "platform" |
| 18 | + |
| 19 | + # Test default labels are applied to Pod template |
| 20 | + - it: should apply default labels to Pod template metadata |
| 21 | + set: |
| 22 | + defaults.labels: |
| 23 | + custom-label: "default-value" |
| 24 | + team: "platform" |
| 25 | + asserts: |
| 26 | + - equal: |
| 27 | + path: spec.template.metadata.labels["custom-label"] |
| 28 | + value: "default-value" |
| 29 | + - equal: |
| 30 | + path: spec.template.metadata.labels["team"] |
| 31 | + value: "platform" |
| 32 | + |
| 33 | + # Test component-specific labels override defaults |
| 34 | + - it: should merge component-specific labels with defaults on Job metadata |
| 35 | + set: |
| 36 | + defaults.labels: |
| 37 | + custom-label: "default-value" |
| 38 | + team: "platform" |
| 39 | + components.miscellaneous.configLoader.labels: |
| 40 | + custom-label: "overridden-value" |
| 41 | + environment: "production" |
| 42 | + asserts: |
| 43 | + - equal: |
| 44 | + path: metadata.labels["custom-label"] |
| 45 | + value: "overridden-value" |
| 46 | + - equal: |
| 47 | + path: metadata.labels["team"] |
| 48 | + value: "platform" |
| 49 | + - equal: |
| 50 | + path: metadata.labels["environment"] |
| 51 | + value: "production" |
| 52 | + |
| 53 | + # Test component-specific labels override defaults on Pod template |
| 54 | + - it: should merge component-specific labels with defaults on Pod template metadata |
| 55 | + set: |
| 56 | + defaults.labels: |
| 57 | + custom-label: "default-value" |
| 58 | + team: "platform" |
| 59 | + components.miscellaneous.configLoader.labels: |
| 60 | + custom-label: "overridden-value" |
| 61 | + environment: "production" |
| 62 | + asserts: |
| 63 | + - equal: |
| 64 | + path: spec.template.metadata.labels["custom-label"] |
| 65 | + value: "overridden-value" |
| 66 | + - equal: |
| 67 | + path: spec.template.metadata.labels["team"] |
| 68 | + value: "platform" |
| 69 | + - equal: |
| 70 | + path: spec.template.metadata.labels["environment"] |
| 71 | + value: "production" |
| 72 | + |
| 73 | + # Test default annotations are applied |
| 74 | + - it: should apply default annotations to Job metadata |
| 75 | + set: |
| 76 | + defaults.annotations: |
| 77 | + prometheus.io/scrape: "true" |
| 78 | + monitoring.io/alert: "critical" |
| 79 | + asserts: |
| 80 | + - equal: |
| 81 | + path: metadata.annotations["prometheus.io/scrape"] |
| 82 | + value: "true" |
| 83 | + - equal: |
| 84 | + path: metadata.annotations["monitoring.io/alert"] |
| 85 | + value: "critical" |
| 86 | + |
| 87 | + # Test default annotations are applied to Pod template |
| 88 | + - it: should apply default annotations to Pod template metadata |
| 89 | + set: |
| 90 | + defaults.annotations: |
| 91 | + prometheus.io/scrape: "true" |
| 92 | + monitoring.io/alert: "critical" |
| 93 | + asserts: |
| 94 | + - equal: |
| 95 | + path: spec.template.metadata.annotations["prometheus.io/scrape"] |
| 96 | + value: "true" |
| 97 | + - equal: |
| 98 | + path: spec.template.metadata.annotations["monitoring.io/alert"] |
| 99 | + value: "critical" |
| 100 | + |
| 101 | + # Test component-specific annotations override defaults |
| 102 | + - it: should merge component-specific annotations with defaults on Job metadata |
| 103 | + set: |
| 104 | + defaults.annotations: |
| 105 | + prometheus.io/scrape: "true" |
| 106 | + monitoring.io/alert: "critical" |
| 107 | + components.miscellaneous.configLoader.annotations: |
| 108 | + prometheus.io/scrape: "false" |
| 109 | + custom.io/annotation: "value" |
| 110 | + asserts: |
| 111 | + - equal: |
| 112 | + path: metadata.annotations["prometheus.io/scrape"] |
| 113 | + value: "false" |
| 114 | + - equal: |
| 115 | + path: metadata.annotations["monitoring.io/alert"] |
| 116 | + value: "critical" |
| 117 | + - equal: |
| 118 | + path: metadata.annotations["custom.io/annotation"] |
| 119 | + value: "value" |
| 120 | + |
| 121 | + # Test component-specific annotations override defaults on Pod template |
| 122 | + - it: should merge component-specific annotations with defaults on Pod template metadata |
| 123 | + set: |
| 124 | + defaults.annotations: |
| 125 | + prometheus.io/scrape: "true" |
| 126 | + monitoring.io/alert: "critical" |
| 127 | + components.miscellaneous.configLoader.annotations: |
| 128 | + prometheus.io/scrape: "false" |
| 129 | + custom.io/annotation: "value" |
| 130 | + asserts: |
| 131 | + - equal: |
| 132 | + path: spec.template.metadata.annotations["prometheus.io/scrape"] |
| 133 | + value: "false" |
| 134 | + - equal: |
| 135 | + path: spec.template.metadata.annotations["monitoring.io/alert"] |
| 136 | + value: "critical" |
| 137 | + - equal: |
| 138 | + path: spec.template.metadata.annotations["custom.io/annotation"] |
| 139 | + value: "value" |
| 140 | + |
| 141 | + # Test empty labels and annotations |
| 142 | + - it: should work with empty labels and annotations |
| 143 | + set: |
| 144 | + defaults.labels: {} |
| 145 | + defaults.annotations: {} |
| 146 | + components.miscellaneous.configLoader.labels: {} |
| 147 | + components.miscellaneous.configLoader.annotations: {} |
| 148 | + asserts: |
| 149 | + - isKind: |
| 150 | + of: Job |
| 151 | + |
| 152 | + # Test only component-specific labels without defaults |
| 153 | + - it: should apply only component-specific labels when defaults are empty |
| 154 | + set: |
| 155 | + defaults.labels: {} |
| 156 | + components.miscellaneous.configLoader.labels: |
| 157 | + component-label: "config-loader" |
| 158 | + version: "1.0" |
| 159 | + asserts: |
| 160 | + - equal: |
| 161 | + path: metadata.labels["component-label"] |
| 162 | + value: "config-loader" |
| 163 | + - equal: |
| 164 | + path: metadata.labels["version"] |
| 165 | + value: "1.0" |
| 166 | + |
| 167 | + # Test only component-specific annotations without defaults |
| 168 | + - it: should apply only component-specific annotations when defaults are empty |
| 169 | + set: |
| 170 | + defaults.annotations: {} |
| 171 | + components.miscellaneous.configLoader.annotations: |
| 172 | + component-annotation: "config-loader" |
| 173 | + build: "12345" |
| 174 | + asserts: |
| 175 | + - equal: |
| 176 | + path: metadata.annotations["component-annotation"] |
| 177 | + value: "config-loader" |
| 178 | + - equal: |
| 179 | + path: metadata.annotations["build"] |
| 180 | + value: "12345" |
| 181 | + |
| 182 | + # Test checksum annotation is preserved |
| 183 | + - it: should preserve checksum annotation along with custom annotations |
| 184 | + set: |
| 185 | + defaults.annotations: |
| 186 | + custom: "value" |
| 187 | + components.miscellaneous.configLoader.annotations: |
| 188 | + another: "annotation" |
| 189 | + asserts: |
| 190 | + - isNotEmpty: |
| 191 | + path: metadata.annotations["checksum/values"] |
| 192 | + - equal: |
| 193 | + path: metadata.annotations["custom"] |
| 194 | + value: "value" |
| 195 | + - equal: |
| 196 | + path: metadata.annotations["another"] |
| 197 | + value: "annotation" |
| 198 | + |
| 199 | + # Test app.kubernetes.io/component label is set correctly |
| 200 | + - it: should set app.kubernetes.io/component label to config-loader |
| 201 | + asserts: |
| 202 | + - equal: |
| 203 | + path: metadata.labels["app.kubernetes.io/component"] |
| 204 | + value: "config-loader" |
| 205 | + - equal: |
| 206 | + path: spec.template.metadata.labels["app.kubernetes.io/component"] |
| 207 | + value: "config-loader" |
0 commit comments