• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zalando-incubator / stackset-controller / 8190225339

07 Mar 2024 03:00PM UTC coverage: 51.299% (-1.0%) from 52.279%
8190225339

Pull #593

github

linki
add inline solution for versioned configmaps
Pull Request #593: [2/3] Add Inline Solution for ConfigMaps

5 of 127 new or added lines in 5 files covered. (3.94%)

53 existing lines in 2 files now uncovered.

3081 of 6006 relevant lines covered (51.3%)

0.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.72
/pkg/core/stack_resources.go
1
package core
2

3
import (
4
        "fmt"
5
        "sort"
6
        "strconv"
7
        "strings"
8

9
        log "github.com/sirupsen/logrus"
10
        rgv1 "github.com/szuecs/routegroup-client/apis/zalando.org/v1"
11
        zv1 "github.com/zalando-incubator/stackset-controller/pkg/apis/zalando.org/v1"
12
        appsv1 "k8s.io/api/apps/v1"
13
        autoscaling "k8s.io/api/autoscaling/v2"
14
        v1 "k8s.io/api/core/v1"
15
        networking "k8s.io/api/networking/v1"
16
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
        "k8s.io/apimachinery/pkg/labels"
18
        "k8s.io/apimachinery/pkg/util/intstr"
19
        "k8s.io/apimachinery/pkg/util/sets"
20
)
21

22
const (
23
        apiVersionAppsV1 = "apps/v1"
24
        kindDeployment   = "Deployment"
25

26
        SegmentSuffix       = "-traffic-segment"
27
        IngressPredicateKey = "zalando.org/skipper-predicate"
28
)
29

30
type ingressOrRouteGroupSpec interface {
31
        GetAnnotations() map[string]string
32
        GetHosts() []string
33
}
34

35
var (
36
        // set implementation with 0 Byte value
37
        selectorLabels = map[string]struct{}{
38
                StacksetHeritageLabelKey: {},
39
                StackVersionLabelKey:     {},
40
        }
41

42
        // PathTypeImplementationSpecific is the used implementation path type
43
        // for k8s.io/api/networking/v1.HTTPIngressPath resources.
44
        PathTypeImplementationSpecific = networking.PathTypeImplementationSpecific
45
)
46

47
func mapCopy(m map[string]string) map[string]string {
1✔
48
        newMap := map[string]string{}
1✔
49
        for k, v := range m {
2✔
50
                newMap[k] = v
1✔
51
        }
1✔
52
        return newMap
1✔
53
}
54

55
// limitLabels returns a limited set of labels based on the validKeys.
56
func limitLabels(labels map[string]string, validKeys map[string]struct{}) map[string]string {
1✔
57
        newLabels := make(map[string]string, len(labels))
1✔
58
        for k, v := range labels {
2✔
59
                if _, ok := validKeys[k]; ok {
2✔
60
                        newLabels[k] = v
1✔
61
                }
1✔
62
        }
63
        return newLabels
1✔
64
}
65

66
// templateObjectMetaInjectLabels injects labels into a pod template spec.
67
func objectMetaInjectLabels(objectMeta metav1.ObjectMeta, labels map[string]string) metav1.ObjectMeta {
1✔
68
        if objectMeta.Labels == nil {
2✔
69
                objectMeta.Labels = map[string]string{}
1✔
70
        }
1✔
71
        for key, value := range labels {
2✔
72
                if _, ok := objectMeta.Labels[key]; !ok {
2✔
73
                        objectMeta.Labels[key] = value
1✔
74
                }
1✔
75
        }
76
        return objectMeta
1✔
77
}
78

79
func (sc *StackContainer) objectMeta(segment bool) metav1.ObjectMeta {
1✔
80
        resourceLabels := mapCopy(sc.Stack.Labels)
1✔
81

1✔
82
        name := sc.Name()
1✔
83
        if segment {
2✔
84
                name += SegmentSuffix
1✔
85
        }
1✔
86

87
        return metav1.ObjectMeta{
1✔
88
                Name:      name,
1✔
89
                Namespace: sc.Namespace(),
1✔
90
                Annotations: map[string]string{
1✔
91
                        stackGenerationAnnotationKey: strconv.FormatInt(sc.Stack.Generation, 10),
1✔
92
                },
1✔
93
                Labels: resourceLabels,
1✔
94
                OwnerReferences: []metav1.OwnerReference{
1✔
95
                        {
1✔
96
                                APIVersion: APIVersion,
1✔
97
                                Kind:       KindStack,
1✔
98
                                Name:       sc.Name(),
1✔
99
                                UID:        sc.Stack.UID,
1✔
100
                        },
1✔
101
                },
1✔
102
        }
1✔
103
}
104

105
func (sc *StackContainer) resourceMeta() metav1.ObjectMeta {
1✔
106
        return sc.objectMeta(false)
1✔
107
}
1✔
108

109
// getServicePorts gets the service ports to be used for the stack service.
110
func getServicePorts(stackSpec zv1.StackSpecInternal, backendPort *intstr.IntOrString) ([]v1.ServicePort, error) {
1✔
111
        var servicePorts []v1.ServicePort
1✔
112
        if stackSpec.StackSpec.Service == nil ||
1✔
113
                len(stackSpec.StackSpec.Service.Ports) == 0 {
2✔
114

1✔
115
                servicePorts = servicePortsFromContainers(
1✔
116
                        stackSpec.StackSpec.PodTemplate.Spec.Containers,
1✔
117
                )
1✔
118
        } else {
2✔
119
                servicePorts = stackSpec.StackSpec.Service.Ports
1✔
120
        }
1✔
121

122
        // validate that one port in the list maps to the backendPort.
123
        if backendPort != nil {
2✔
124
                for _, port := range servicePorts {
2✔
125
                        switch backendPort.Type {
1✔
126
                        case intstr.Int:
1✔
127
                                if port.Port == backendPort.IntVal {
2✔
128
                                        return servicePorts, nil
1✔
129
                                }
1✔
130
                        case intstr.String:
1✔
131
                                if port.Name == backendPort.StrVal {
2✔
132
                                        return servicePorts, nil
1✔
133
                                }
1✔
134
                        }
135
                }
136

137
                return nil, fmt.Errorf("no service ports matching backendPort '%s'", backendPort.String())
1✔
138
        }
139

140
        return servicePorts, nil
1✔
141
}
142

143
// servicePortsFromTemplate gets service port from pod template.
144
func servicePortsFromContainers(containers []v1.Container) []v1.ServicePort {
1✔
145
        ports := make([]v1.ServicePort, 0)
1✔
146
        for i, container := range containers {
2✔
147
                for j, port := range container.Ports {
2✔
148
                        name := fmt.Sprintf("port-%d-%d", i, j)
1✔
149
                        if port.Name != "" {
2✔
150
                                name = port.Name
1✔
151
                        }
1✔
152
                        servicePort := v1.ServicePort{
1✔
153
                                Name:       name,
1✔
154
                                Protocol:   port.Protocol,
1✔
155
                                Port:       port.ContainerPort,
1✔
156
                                TargetPort: intstr.FromInt(int(port.ContainerPort)),
1✔
157
                        }
1✔
158
                        // set default protocol if not specified
1✔
159
                        if servicePort.Protocol == "" {
2✔
160
                                servicePort.Protocol = v1.ProtocolTCP
1✔
161
                        }
1✔
162
                        ports = append(ports, servicePort)
1✔
163
                }
164
        }
165
        return ports
1✔
166
}
167

168
func (sc *StackContainer) selector() map[string]string {
1✔
169
        return limitLabels(sc.Stack.Labels, selectorLabels)
1✔
170
}
1✔
171

172
func (sc *StackContainer) GenerateDeployment() *appsv1.Deployment {
1✔
173
        stack := sc.Stack
1✔
174

1✔
175
        desiredReplicas := sc.stackReplicas
1✔
176
        if sc.prescalingActive {
2✔
177
                desiredReplicas = sc.prescalingReplicas
1✔
178
        }
1✔
179

180
        var updatedReplicas *int32
1✔
181

1✔
182
        if desiredReplicas != 0 && !sc.ScaledDown() {
2✔
183
                // Stack scaled up, rescale the deployment if it's at 0 replicas, or if HPA is unused and we don't run autoscaling
1✔
184
                if sc.deploymentReplicas == 0 || (!sc.IsAutoscaled() && desiredReplicas != sc.deploymentReplicas) {
2✔
185
                        updatedReplicas = wrapReplicas(desiredReplicas)
1✔
186
                }
1✔
187
        } else {
1✔
188
                // Stack scaled down (manually or because it doesn't receive traffic), check if we need to scale down the deployment
1✔
189
                if sc.deploymentReplicas != 0 {
2✔
190
                        updatedReplicas = wrapReplicas(0)
1✔
191
                }
1✔
192
        }
193

194
        if updatedReplicas == nil {
2✔
195
                updatedReplicas = wrapReplicas(sc.deploymentReplicas)
1✔
196
        }
1✔
197

198
        var strategy *appsv1.DeploymentStrategy
1✔
199
        if stack.Spec.StackSpec.Strategy != nil {
2✔
200
                strategy = stack.Spec.StackSpec.Strategy.DeepCopy()
1✔
201
        }
1✔
202

203
        embeddedCopy := stack.Spec.StackSpec.PodTemplate.EmbeddedObjectMeta.DeepCopy()
1✔
204

1✔
205
        templateObjectMeta := metav1.ObjectMeta{
1✔
206
                Annotations: embeddedCopy.Annotations,
1✔
207
                Labels:      embeddedCopy.Labels,
1✔
208
        }
1✔
209

1✔
210
        deployment := &appsv1.Deployment{
1✔
211
                ObjectMeta: sc.resourceMeta(),
1✔
212
                Spec: appsv1.DeploymentSpec{
1✔
213
                        Replicas:        updatedReplicas,
1✔
214
                        MinReadySeconds: sc.Stack.Spec.StackSpec.MinReadySeconds,
1✔
215
                        Selector: &metav1.LabelSelector{
1✔
216
                                MatchLabels: sc.selector(),
1✔
217
                        },
1✔
218
                        Template: v1.PodTemplateSpec{
1✔
219
                                ObjectMeta: objectMetaInjectLabels(templateObjectMeta, stack.Labels),
1✔
220
                                Spec:       *stack.Spec.StackSpec.PodTemplate.Spec.DeepCopy(),
1✔
221
                        },
1✔
222
                },
1✔
223
        }
1✔
224
        if strategy != nil {
2✔
225
                deployment.Spec.Strategy = *strategy
1✔
226
        }
1✔
227
        return deployment
1✔
228
}
229

230
func (sc *StackContainer) GenerateHPAToSegment() (
231
        *autoscaling.HorizontalPodAutoscaler,
232
        error,
233
) {
1✔
234
        return sc.generateHPA(true)
1✔
235
}
1✔
236

237
func (sc *StackContainer) GenerateHPA() (
238
        *autoscaling.HorizontalPodAutoscaler,
239
        error,
240
) {
1✔
241
        return sc.generateHPA(false)
1✔
242

1✔
243
}
1✔
244

245
func (sc *StackContainer) generateHPA(toSegment bool) (
246
        *autoscaling.HorizontalPodAutoscaler,
247
        error,
248
) {
1✔
249
        autoscalerSpec := sc.Stack.Spec.StackSpec.Autoscaler
1✔
250
        trafficWeight := sc.actualTrafficWeight
1✔
251

1✔
252
        if autoscalerSpec == nil {
1✔
UNCOV
253
                return nil, nil
×
UNCOV
254
        }
×
255

256
        result := &autoscaling.HorizontalPodAutoscaler{
1✔
257
                ObjectMeta: sc.resourceMeta(),
1✔
258
                TypeMeta: metav1.TypeMeta{
1✔
259
                        Kind:       "HorizontalPodAutoscaler",
1✔
260
                        APIVersion: "autoscaling/v2",
1✔
261
                },
1✔
262
                Spec: autoscaling.HorizontalPodAutoscalerSpec{
1✔
263
                        ScaleTargetRef: autoscaling.CrossVersionObjectReference{
1✔
264
                                APIVersion: apiVersionAppsV1,
1✔
265
                                Kind:       kindDeployment,
1✔
266
                                Name:       sc.Name(),
1✔
267
                        },
1✔
268
                },
1✔
269
        }
1✔
270

1✔
271
        result.Spec.MinReplicas = autoscalerSpec.MinReplicas
1✔
272
        result.Spec.MaxReplicas = autoscalerSpec.MaxReplicas
1✔
273

1✔
274
        ingressResourceName := sc.stacksetName
1✔
275
        if toSegment {
2✔
276
                ingressResourceName = sc.Name() + SegmentSuffix
1✔
277
        }
1✔
278

279
        metrics, annotations, err := convertCustomMetrics(
1✔
280
                ingressResourceName,
1✔
281
                sc.Name(),
1✔
282
                sc.Namespace(),
1✔
283
                autoscalerMetricsList(autoscalerSpec.Metrics),
1✔
284
                trafficWeight,
1✔
285
        )
1✔
286

1✔
287
        if err != nil {
1✔
UNCOV
288
                return nil, err
×
UNCOV
289
        }
×
290
        result.Spec.Metrics = metrics
1✔
291
        result.Annotations = mergeLabels(result.Annotations, annotations)
1✔
292
        result.Spec.Behavior = autoscalerSpec.Behavior
1✔
293

1✔
294
        // If prescaling is enabled, ensure we have at least `precalingReplicas` pods
1✔
295
        if sc.prescalingActive && (result.Spec.MinReplicas == nil || *result.Spec.MinReplicas < sc.prescalingReplicas) {
1✔
UNCOV
296
                pr := sc.prescalingReplicas
×
UNCOV
297
                result.Spec.MinReplicas = &pr
×
298
        }
×
299

300
        return result, nil
1✔
301
}
302

303
func (sc *StackContainer) GenerateService() (*v1.Service, error) {
1✔
304
        // get service ports to be used for the service
1✔
305
        var backendPort *intstr.IntOrString
1✔
306
        // Ingress or external managed Ingress
1✔
307
        if sc.HasBackendPort() {
1✔
UNCOV
308
                backendPort = sc.backendPort
×
UNCOV
309
        }
×
310

311
        servicePorts, err := getServicePorts(sc.Stack.Spec, backendPort)
1✔
312
        if err != nil {
1✔
UNCOV
313
                return nil, err
×
UNCOV
314
        }
×
315

316
        metaObj := sc.resourceMeta()
1✔
317
        stackSpec := sc.Stack.Spec
1✔
318
        if stackSpec.StackSpec.Service != nil {
2✔
319
                metaObj.Annotations = mergeLabels(
1✔
320
                        metaObj.Annotations,
1✔
321
                        stackSpec.StackSpec.Service.Annotations,
1✔
322
                )
1✔
323
        }
1✔
324
        return &v1.Service{
1✔
325
                ObjectMeta: metaObj,
1✔
326
                Spec: v1.ServiceSpec{
1✔
327
                        Selector: sc.selector(),
1✔
328
                        Type:     v1.ServiceTypeClusterIP,
1✔
329
                        Ports:    servicePorts,
1✔
330
                },
1✔
331
        }, nil
1✔
332
}
333

334
func (sc *StackContainer) stackHostnames(
335
        spec ingressOrRouteGroupSpec,
336
        segment bool,
337
) ([]string, error) {
1✔
338
        // The Ingress segment uses the original hostnames
1✔
339
        if segment {
2✔
340
                return spec.GetHosts(), nil
1✔
341
        }
1✔
342
        result := sets.NewString()
1✔
343

1✔
344
        // Old-style autogenerated hostnames
1✔
345
        for _, host := range spec.GetHosts() {
2✔
346
                for _, domain := range sc.clusterDomains {
2✔
347
                        if strings.HasSuffix(host, domain) {
2✔
348
                                result.Insert(fmt.Sprintf("%s.%s", sc.Name(), domain))
1✔
349
                        } else {
2✔
350
                                log.Debugf(
1✔
351
                                        "Ingress host: %s suffix did not match cluster-domain %s",
1✔
352
                                        host,
1✔
353
                                        domain,
1✔
354
                                )
1✔
355
                        }
1✔
356
                }
357
        }
358
        return result.List(), nil
1✔
359
}
360

361
func (sc *StackContainer) GenerateIngress() (*networking.Ingress, error) {
1✔
362
        return sc.generateIngress(false)
1✔
363
}
1✔
364

365
func (sc *StackContainer) GenerateIngressSegment() (
366
        *networking.Ingress,
367
        error,
368
) {
1✔
369
        res, err := sc.generateIngress(true)
1✔
370
        if err != nil || res == nil {
2✔
371
                return res, err
1✔
372
        }
1✔
373

374
        // Synchronize annotations specified in the StackSet.
375
        res.Annotations = syncAnnotations(
1✔
376
                res.Annotations,
1✔
377
                sc.syncAnnotationsInIngress,
1✔
378
                sc.ingressAnnotationsToSync,
1✔
379
        )
1✔
380

1✔
381
        if predVal, ok := res.Annotations[IngressPredicateKey]; !ok || predVal == "" {
2✔
382
                res.Annotations = mergeLabels(
1✔
383
                        res.Annotations,
1✔
384
                        map[string]string{IngressPredicateKey: sc.trafficSegment()},
1✔
385
                )
1✔
386
        } else {
2✔
387
                res.Annotations = mergeLabels(
1✔
388
                        res.Annotations,
1✔
389
                        map[string]string{
1✔
390
                                IngressPredicateKey: sc.trafficSegment() + " && " + predVal,
1✔
391
                        },
1✔
392
                )
1✔
393
        }
1✔
394

395
        return res, nil
1✔
396
}
397

398
func (sc *StackContainer) generateIngress(segment bool) (
399
        *networking.Ingress,
400
        error,
401
) {
1✔
402

1✔
403
        if !sc.HasBackendPort() || sc.ingressSpec == nil {
2✔
404
                return nil, nil
1✔
405
        }
1✔
406

407
        hostnames, err := sc.stackHostnames(sc.ingressSpec, segment)
1✔
408
        if err != nil {
1✔
UNCOV
409
                return nil, err
×
UNCOV
410
        }
×
411
        if len(hostnames) == 0 {
2✔
412
                return nil, nil
1✔
413
        }
1✔
414

415
        rules := make([]networking.IngressRule, 0, len(hostnames))
1✔
416
        for _, hostname := range hostnames {
2✔
417
                rules = append(rules, networking.IngressRule{
1✔
418
                        IngressRuleValue: networking.IngressRuleValue{
1✔
419
                                HTTP: &networking.HTTPIngressRuleValue{
1✔
420
                                        Paths: []networking.HTTPIngressPath{
1✔
421
                                                {
1✔
422
                                                        PathType: &PathTypeImplementationSpecific,
1✔
423
                                                        Path:     sc.ingressSpec.Path,
1✔
424
                                                        Backend: networking.IngressBackend{
1✔
425
                                                                Service: &networking.IngressServiceBackend{
1✔
426
                                                                        Name: sc.Name(),
1✔
427
                                                                        Port: networking.ServiceBackendPort{
1✔
428
                                                                                Name:   sc.backendPort.StrVal,
1✔
429
                                                                                Number: sc.backendPort.IntVal,
1✔
430
                                                                        },
1✔
431
                                                                },
1✔
432
                                                        },
1✔
433
                                                },
1✔
434
                                        },
1✔
435
                                },
1✔
436
                        },
1✔
437
                        Host: hostname,
1✔
438
                })
1✔
439
        }
1✔
440

441
        // sort rules by hostname for a stable order
442
        sort.Slice(rules, func(i, j int) bool {
2✔
443
                return rules[i].Host < rules[j].Host
1✔
444
        })
1✔
445

446
        result := &networking.Ingress{
1✔
447
                ObjectMeta: sc.objectMeta(segment),
1✔
448
                Spec: networking.IngressSpec{
1✔
449
                        Rules: rules,
1✔
450
                },
1✔
451
        }
1✔
452

1✔
453
        // insert annotations
1✔
454
        result.Annotations = mergeLabels(
1✔
455
                result.Annotations,
1✔
456
                sc.ingressSpec.GetAnnotations(),
1✔
457
        )
1✔
458

1✔
459
        return result, nil
1✔
460
}
461

462
func (sc *StackContainer) GenerateRouteGroup() (*rgv1.RouteGroup, error) {
1✔
463
        return sc.generateRouteGroup(false)
1✔
464
}
1✔
465

466
func (sc *StackContainer) GenerateRouteGroupSegment() (
467
        *rgv1.RouteGroup,
468
        error,
469
) {
1✔
470
        res, err := sc.generateRouteGroup(true)
1✔
471
        if err != nil || res == nil {
2✔
472
                return res, err
1✔
473
        }
1✔
474

475
        // Synchronize annotations specified in the StackSet.
476
        res.Annotations = syncAnnotations(
1✔
477
                res.Annotations,
1✔
478
                sc.syncAnnotationsInRouteGroup,
1✔
479
                sc.ingressAnnotationsToSync,
1✔
480
        )
1✔
481

1✔
482
        segmentedRoutes := []rgv1.RouteGroupRouteSpec{}
1✔
483
        for _, r := range res.Spec.Routes {
2✔
484
                r.Predicates = append(r.Predicates, sc.trafficSegment())
1✔
485
                segmentedRoutes = append(segmentedRoutes, r)
1✔
486
        }
1✔
487
        res.Spec.Routes = segmentedRoutes
1✔
488

1✔
489
        return res, nil
1✔
490
}
491

492
func (sc *StackContainer) generateRouteGroup(segment bool) (
493
        *rgv1.RouteGroup,
494
        error,
495
) {
1✔
496
        if !sc.HasBackendPort() || sc.routeGroupSpec == nil {
2✔
497
                return nil, nil
1✔
498
        }
1✔
499

500
        hostnames, err := sc.stackHostnames(sc.routeGroupSpec, segment)
1✔
501
        if err != nil {
1✔
UNCOV
502
                return nil, err
×
UNCOV
503
        }
×
504
        if len(hostnames) == 0 {
2✔
505
                return nil, nil
1✔
506
        }
1✔
507

508
        result := &rgv1.RouteGroup{
1✔
509
                ObjectMeta: sc.objectMeta(segment),
1✔
510
                Spec: rgv1.RouteGroupSpec{
1✔
511
                        Hosts: hostnames,
1✔
512
                        Backends: []rgv1.RouteGroupBackend{
1✔
513
                                {
1✔
514
                                        Name:        sc.Name(),
1✔
515
                                        Type:        rgv1.ServiceRouteGroupBackend,
1✔
516
                                        ServiceName: sc.Name(),
1✔
517
                                        ServicePort: sc.backendPort.IntValue(),
1✔
518
                                        Algorithm:   sc.routeGroupSpec.LBAlgorithm,
1✔
519
                                },
1✔
520
                        },
1✔
521
                        DefaultBackends: []rgv1.RouteGroupBackendReference{
1✔
522
                                {
1✔
523
                                        BackendName: sc.Name(),
1✔
524
                                        Weight:      100,
1✔
525
                                },
1✔
526
                        },
1✔
527
                },
1✔
528
        }
1✔
529

1✔
530
        result.Spec.Routes = sc.routeGroupSpec.Routes
1✔
531

1✔
532
        // validate not overlapping with main backend
1✔
533
        for _, backend := range sc.routeGroupSpec.AdditionalBackends {
1✔
UNCOV
534
                if backend.Name == sc.Name() {
×
UNCOV
535
                        return nil, fmt.Errorf("invalid additionalBackend '%s', overlaps with Stack name", backend.Name)
×
536
                }
×
537
                if backend.ServiceName == sc.Name() {
×
538
                        return nil, fmt.Errorf("invalid additionalBackend '%s', serviceName '%s' overlaps with Stack name", backend.Name, backend.ServiceName)
×
539
                }
×
540
                result.Spec.Backends = append(result.Spec.Backends, backend)
×
541
        }
542

543
        // sort backends to ensure have a consistent generated RouteGroup resource
544
        sort.Slice(result.Spec.Backends, func(i, j int) bool {
1✔
UNCOV
545
                return result.Spec.Backends[i].Name < result.Spec.Backends[j].Name
×
UNCOV
546
        })
×
547

548
        // insert annotations
549
        result.Annotations = mergeLabels(
1✔
550
                result.Annotations,
1✔
551
                sc.routeGroupSpec.GetAnnotations(),
1✔
552
        )
1✔
553

1✔
554
        return result, nil
1✔
555
}
556

557
func (sc *StackContainer) trafficSegment() string {
1✔
558
        return fmt.Sprintf(
1✔
559
                segmentString,
1✔
560
                sc.segmentLowerLimit,
1✔
561
                sc.segmentUpperLimit,
1✔
562
        )
1✔
563
}
1✔
564

565
func (sc *StackContainer) UpdateObjectMeta(objMeta *metav1.ObjectMeta) *metav1.ObjectMeta {
1✔
566
        metaObj := sc.resourceMeta()
1✔
567
        objMeta.OwnerReferences = metaObj.OwnerReferences
1✔
568
        objMeta.Labels = mergeLabels(metaObj.Labels, objMeta.Labels)
1✔
569
        objMeta.Annotations = mergeLabels(metaObj.Annotations, objMeta.Annotations)
1✔
570

1✔
571
        return objMeta
1✔
572
}
1✔
573

NEW
UNCOV
574
func (sc *StackContainer) GenerateConfigMaps() ([]*v1.ConfigMap, error) {
×
NEW
UNCOV
575
        result := []*v1.ConfigMap{}
×
NEW
UNCOV
576

×
NEW
UNCOV
577
        for _, configResource := range sc.Stack.Spec.ConfigurationResources {
×
NEW
UNCOV
578
                if !configResource.IsConfigMap() {
×
NEW
UNCOV
579
                        continue
×
580
                }
581

NEW
582
                metaObj := sc.resourceMeta()
×
NEW
583
                metaObj.Name = metaObj.Name + "-" + configResource.GetName()
×
NEW
584
                metaObj.OwnerReferences = []metav1.OwnerReference{
×
NEW
585
                        {
×
NEW
586
                                APIVersion: "zalando.org/v1",
×
NEW
587
                                Kind:       "Stack",
×
NEW
588
                                Name:       sc.Name(),
×
NEW
589
                                UID:        sc.Stack.UID,
×
NEW
590
                        },
×
NEW
591
                }
×
NEW
592

×
NEW
593
                base := &v1.ConfigMap{
×
NEW
594
                        ObjectMeta: metaObj,
×
NEW
595
                        Data:       configResource.ConfigMap.Data,
×
NEW
596
                }
×
NEW
597

×
NEW
598
                result = append(result, base)
×
599
        }
600

NEW
601
        return result, nil
×
602
}
603

604
func (sc *StackContainer) GenerateStackStatus() *zv1.StackStatus {
1✔
605
        prescaling := zv1.PrescalingStatus{}
1✔
606
        if sc.prescalingActive {
2✔
607
                prescaling = zv1.PrescalingStatus{
1✔
608
                        Active:               sc.prescalingActive,
1✔
609
                        Replicas:             sc.prescalingReplicas,
1✔
610
                        DesiredTrafficWeight: sc.prescalingDesiredTrafficWeight,
1✔
611
                        LastTrafficIncrease:  wrapTime(sc.prescalingLastTrafficIncrease),
1✔
612
                }
1✔
613
        }
1✔
614
        return &zv1.StackStatus{
1✔
615
                ActualTrafficWeight:  sc.actualTrafficWeight,
1✔
616
                DesiredTrafficWeight: sc.desiredTrafficWeight,
1✔
617
                Replicas:             sc.createdReplicas,
1✔
618
                ReadyReplicas:        sc.readyReplicas,
1✔
619
                UpdatedReplicas:      sc.updatedReplicas,
1✔
620
                DesiredReplicas:      sc.deploymentReplicas,
1✔
621
                Prescaling:           prescaling,
1✔
622
                NoTrafficSince:       wrapTime(sc.noTrafficSince),
1✔
623
                LabelSelector:        labels.Set(sc.selector()).String(),
1✔
624
        }
1✔
625
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc