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

zalando-incubator / stackset-controller / 8344206413

19 Mar 2024 01:49PM UTC coverage: 51.323% (-1.0%) from 52.337%
8344206413

Pull #593

github

linki
add section in e2e sample to test inline configmaps
Pull Request #593: [2/3] Add Inline Solution for ConfigMaps

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

49 existing lines in 2 files now uncovered.

3084 of 6009 relevant lines covered (51.32%)

0.58 hits per line

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

89.79
/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
        if sc.ScaledDown() {
2✔
257
                return nil, nil
1✔
258
        }
1✔
259

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

1✔
275
        result.Spec.MinReplicas = autoscalerSpec.MinReplicas
1✔
276
        result.Spec.MaxReplicas = autoscalerSpec.MaxReplicas
1✔
277

1✔
278
        ingressResourceName := sc.stacksetName
1✔
279
        if toSegment {
2✔
280
                ingressResourceName = sc.Name() + SegmentSuffix
1✔
281
        }
1✔
282

283
        metrics, annotations, err := convertCustomMetrics(
1✔
284
                ingressResourceName,
1✔
285
                sc.Name(),
1✔
286
                sc.Namespace(),
1✔
287
                autoscalerMetricsList(autoscalerSpec.Metrics),
1✔
288
                trafficWeight,
1✔
289
        )
1✔
290

1✔
291
        if err != nil {
1✔
UNCOV
292
                return nil, err
×
UNCOV
293
        }
×
294
        result.Spec.Metrics = metrics
1✔
295
        result.Annotations = mergeLabels(result.Annotations, annotations)
1✔
296
        result.Spec.Behavior = autoscalerSpec.Behavior
1✔
297

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

304
        return result, nil
1✔
305
}
306

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

315
        servicePorts, err := getServicePorts(sc.Stack.Spec, backendPort)
1✔
316
        if err != nil {
1✔
UNCOV
317
                return nil, err
×
UNCOV
318
        }
×
319

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

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

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

365
func (sc *StackContainer) GenerateIngress() (*networking.Ingress, error) {
1✔
366
        return sc.generateIngress(false)
1✔
367
}
1✔
368

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

378
        // Synchronize annotations specified in the StackSet.
379
        res.Annotations = syncAnnotations(
1✔
380
                res.Annotations,
1✔
381
                sc.syncAnnotationsInIngress,
1✔
382
                sc.ingressAnnotationsToSync,
1✔
383
        )
1✔
384

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

399
        return res, nil
1✔
400
}
401

402
func (sc *StackContainer) generateIngress(segment bool) (
403
        *networking.Ingress,
404
        error,
405
) {
1✔
406

1✔
407
        if !sc.HasBackendPort() || sc.ingressSpec == nil {
2✔
408
                return nil, nil
1✔
409
        }
1✔
410

411
        hostnames, err := sc.stackHostnames(sc.ingressSpec, segment)
1✔
412
        if err != nil {
1✔
UNCOV
413
                return nil, err
×
UNCOV
414
        }
×
415
        if len(hostnames) == 0 {
2✔
416
                return nil, nil
1✔
417
        }
1✔
418

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

445
        // sort rules by hostname for a stable order
446
        sort.Slice(rules, func(i, j int) bool {
2✔
447
                return rules[i].Host < rules[j].Host
1✔
448
        })
1✔
449

450
        result := &networking.Ingress{
1✔
451
                ObjectMeta: sc.objectMeta(segment),
1✔
452
                Spec: networking.IngressSpec{
1✔
453
                        Rules: rules,
1✔
454
                },
1✔
455
        }
1✔
456

1✔
457
        // insert annotations
1✔
458
        result.Annotations = mergeLabels(
1✔
459
                result.Annotations,
1✔
460
                sc.ingressSpec.GetAnnotations(),
1✔
461
        )
1✔
462

1✔
463
        return result, nil
1✔
464
}
465

466
func (sc *StackContainer) GenerateRouteGroup() (*rgv1.RouteGroup, error) {
1✔
467
        return sc.generateRouteGroup(false)
1✔
468
}
1✔
469

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

479
        // Synchronize annotations specified in the StackSet.
480
        res.Annotations = syncAnnotations(
1✔
481
                res.Annotations,
1✔
482
                sc.syncAnnotationsInRouteGroup,
1✔
483
                sc.ingressAnnotationsToSync,
1✔
484
        )
1✔
485

1✔
486
        segmentedRoutes := []rgv1.RouteGroupRouteSpec{}
1✔
487
        for _, r := range res.Spec.Routes {
2✔
488
                r.Predicates = append(r.Predicates, sc.trafficSegment())
1✔
489
                segmentedRoutes = append(segmentedRoutes, r)
1✔
490
        }
1✔
491
        res.Spec.Routes = segmentedRoutes
1✔
492

1✔
493
        return res, nil
1✔
494
}
495

496
func (sc *StackContainer) generateRouteGroup(segment bool) (
497
        *rgv1.RouteGroup,
498
        error,
499
) {
1✔
500
        if !sc.HasBackendPort() || sc.routeGroupSpec == nil {
2✔
501
                return nil, nil
1✔
502
        }
1✔
503

504
        hostnames, err := sc.stackHostnames(sc.routeGroupSpec, segment)
1✔
505
        if err != nil {
1✔
UNCOV
506
                return nil, err
×
UNCOV
507
        }
×
508
        if len(hostnames) == 0 {
2✔
509
                return nil, nil
1✔
510
        }
1✔
511

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

1✔
534
        result.Spec.Routes = sc.routeGroupSpec.Routes
1✔
535

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

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

552
        // insert annotations
553
        result.Annotations = mergeLabels(
1✔
554
                result.Annotations,
1✔
555
                sc.routeGroupSpec.GetAnnotations(),
1✔
556
        )
1✔
557

1✔
558
        return result, nil
1✔
559
}
560

561
func (sc *StackContainer) trafficSegment() string {
1✔
562
        return fmt.Sprintf(
1✔
563
                segmentString,
1✔
564
                sc.segmentLowerLimit,
1✔
565
                sc.segmentUpperLimit,
1✔
566
        )
1✔
567
}
1✔
568

569
func (sc *StackContainer) UpdateObjectMeta(objMeta *metav1.ObjectMeta) *metav1.ObjectMeta {
1✔
570
        metaObj := sc.resourceMeta()
1✔
571
        objMeta.OwnerReferences = metaObj.OwnerReferences
1✔
572
        objMeta.Labels = mergeLabels(metaObj.Labels, objMeta.Labels)
1✔
573
        objMeta.Annotations = mergeLabels(metaObj.Annotations, objMeta.Annotations)
1✔
574

1✔
575
        return objMeta
1✔
576
}
1✔
577

NEW
UNCOV
578
func (sc *StackContainer) GenerateConfigMaps() ([]*v1.ConfigMap, error) {
×
NEW
UNCOV
579
        result := []*v1.ConfigMap{}
×
NEW
580

×
NEW
581
        for _, configResource := range sc.Stack.Spec.ConfigurationResources {
×
NEW
582
                if !configResource.IsConfigMap() {
×
NEW
583
                        continue
×
584
                }
585

NEW
586
                metaObj := sc.resourceMeta()
×
NEW
587
                metaObj.Name = metaObj.Name + "-" + configResource.GetName()
×
NEW
588
                metaObj.OwnerReferences = []metav1.OwnerReference{
×
NEW
589
                        {
×
NEW
590
                                APIVersion: APIVersion,
×
NEW
591
                                Kind:       KindStack,
×
NEW
592
                                Name:       sc.Name(),
×
NEW
593
                                UID:        sc.Stack.UID,
×
NEW
594
                        },
×
NEW
595
                }
×
NEW
596

×
NEW
597
                base := &v1.ConfigMap{
×
NEW
598
                        ObjectMeta: metaObj,
×
NEW
599
                        Data:       configResource.ConfigMap.Data,
×
NEW
600
                }
×
NEW
601

×
NEW
602
                result = append(result, base)
×
603
        }
604

NEW
605
        return result, nil
×
606
}
607

608
func (sc *StackContainer) GenerateStackStatus() *zv1.StackStatus {
1✔
609
        prescaling := zv1.PrescalingStatus{}
1✔
610
        if sc.prescalingActive {
2✔
611
                prescaling = zv1.PrescalingStatus{
1✔
612
                        Active:               sc.prescalingActive,
1✔
613
                        Replicas:             sc.prescalingReplicas,
1✔
614
                        DesiredTrafficWeight: sc.prescalingDesiredTrafficWeight,
1✔
615
                        LastTrafficIncrease:  wrapTime(sc.prescalingLastTrafficIncrease),
1✔
616
                }
1✔
617
        }
1✔
618
        return &zv1.StackStatus{
1✔
619
                ActualTrafficWeight:  sc.actualTrafficWeight,
1✔
620
                DesiredTrafficWeight: sc.desiredTrafficWeight,
1✔
621
                Replicas:             sc.createdReplicas,
1✔
622
                ReadyReplicas:        sc.readyReplicas,
1✔
623
                UpdatedReplicas:      sc.updatedReplicas,
1✔
624
                DesiredReplicas:      sc.deploymentReplicas,
1✔
625
                Prescaling:           prescaling,
1✔
626
                NoTrafficSince:       wrapTime(sc.noTrafficSince),
1✔
627
                LabelSelector:        labels.Set(sc.selector()).String(),
1✔
628
        }
1✔
629
}
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