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

zalando-incubator / stackset-controller / 15903028372

26 Jun 2025 01:21PM UTC coverage: 55.363% (-0.06%) from 55.425%
15903028372

Pull #693

github

demonCoder95
fix logic in segment ingresses
Pull Request #693: Make per-stack hostnames configurable

7 of 11 new or added lines in 3 files covered. (63.64%)

2 existing lines in 1 file now uncovered.

3009 of 5435 relevant lines covered (55.36%)

0.62 hits per line

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

93.52
/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) GenerateHPA() (
231
        *autoscaling.HorizontalPodAutoscaler,
232
        error,
233
) {
1✔
234
        autoscalerSpec := sc.Stack.Spec.StackSpec.Autoscaler
1✔
235
        trafficWeight := sc.actualTrafficWeight
1✔
236

1✔
237
        if autoscalerSpec == nil {
1✔
238
                return nil, nil
×
239
        }
×
240

241
        if sc.ScaledDown() {
2✔
242
                return nil, nil
1✔
243
        }
1✔
244

245
        result := &autoscaling.HorizontalPodAutoscaler{
1✔
246
                ObjectMeta: sc.resourceMeta(),
1✔
247
                TypeMeta: metav1.TypeMeta{
1✔
248
                        Kind:       "HorizontalPodAutoscaler",
1✔
249
                        APIVersion: "autoscaling/v2",
1✔
250
                },
1✔
251
                Spec: autoscaling.HorizontalPodAutoscalerSpec{
1✔
252
                        ScaleTargetRef: autoscaling.CrossVersionObjectReference{
1✔
253
                                APIVersion: apiVersionAppsV1,
1✔
254
                                Kind:       kindDeployment,
1✔
255
                                Name:       sc.Name(),
1✔
256
                        },
1✔
257
                },
1✔
258
        }
1✔
259

1✔
260
        result.Spec.MinReplicas = autoscalerSpec.MinReplicas
1✔
261
        result.Spec.MaxReplicas = autoscalerSpec.MaxReplicas
1✔
262

1✔
263
        metrics, annotations, err := convertCustomMetrics(
1✔
264
                sc.Name()+SegmentSuffix,
1✔
265
                sc.Name(),
1✔
266
                sc.Namespace(),
1✔
267
                autoscalerMetricsList(autoscalerSpec.Metrics),
1✔
268
                trafficWeight,
1✔
269
        )
1✔
270

1✔
271
        if err != nil {
1✔
272
                return nil, err
×
273
        }
×
274
        result.Spec.Metrics = metrics
1✔
275
        result.Annotations = mergeLabels(result.Annotations, annotations)
1✔
276
        result.Spec.Behavior = autoscalerSpec.Behavior
1✔
277

1✔
278
        // If prescaling is enabled, ensure we have at least `precalingReplicas` pods
1✔
279
        if sc.prescalingActive && (result.Spec.MinReplicas == nil || *result.Spec.MinReplicas < sc.prescalingReplicas) {
1✔
280
                pr := sc.prescalingReplicas
×
281
                result.Spec.MinReplicas = &pr
×
282
        }
×
283

284
        return result, nil
1✔
285
}
286

287
func (sc *StackContainer) GenerateService() (*v1.Service, error) {
1✔
288
        // get service ports to be used for the service
1✔
289
        var backendPort *intstr.IntOrString
1✔
290
        // Ingress or external managed Ingress
1✔
291
        if sc.HasBackendPort() {
1✔
292
                backendPort = sc.backendPort
×
293
        }
×
294

295
        servicePorts, err := getServicePorts(sc.Stack.Spec, backendPort)
1✔
296
        if err != nil {
1✔
297
                return nil, err
×
298
        }
×
299

300
        metaObj := sc.resourceMeta()
1✔
301
        stackSpec := sc.Stack.Spec
1✔
302
        if stackSpec.StackSpec.Service != nil {
2✔
303
                metaObj.Annotations = mergeLabels(
1✔
304
                        metaObj.Annotations,
1✔
305
                        stackSpec.StackSpec.Service.Annotations,
1✔
306
                )
1✔
307
        }
1✔
308
        return &v1.Service{
1✔
309
                ObjectMeta: metaObj,
1✔
310
                Spec: v1.ServiceSpec{
1✔
311
                        Selector: sc.selector(),
1✔
312
                        Type:     v1.ServiceTypeClusterIP,
1✔
313
                        Ports:    servicePorts,
1✔
314
                },
1✔
315
        }, nil
1✔
316
}
317

318
func (sc *StackContainer) stackHostnames(
319
        spec ingressOrRouteGroupSpec,
320
        segment bool,
321
) ([]string, error) {
1✔
322
        // The Ingress segment uses the original hostnames
1✔
323
        if segment {
2✔
324
                return spec.GetHosts(), nil
1✔
325
        }
1✔
326
        result := sets.NewString()
1✔
327

1✔
328
        // Old-style autogenerated hostnames
1✔
329
        for _, host := range spec.GetHosts() {
2✔
330
                for _, domain := range sc.clusterDomains {
2✔
331
                        if strings.HasSuffix(host, domain) {
2✔
332
                                result.Insert(fmt.Sprintf("%s.%s", sc.Name(), domain))
1✔
333
                        } else {
2✔
334
                                log.Debugf(
1✔
335
                                        "Ingress host: %s suffix did not match cluster-domain %s",
1✔
336
                                        host,
1✔
337
                                        domain,
1✔
338
                                )
1✔
339
                        }
1✔
340
                }
341
        }
342
        return result.List(), nil
1✔
343
}
344

345
func (sc *StackContainer) GenerateIngress(perStackHostnameEnabled bool) (*networking.Ingress, error) {
1✔
346
        return sc.generateIngress(false, perStackHostnameEnabled)
1✔
347
}
1✔
348

349
func (sc *StackContainer) GenerateIngressSegment(perStackHostnameEnabled bool) (
350
        *networking.Ingress,
351
        error,
352
) {
1✔
353
        res, err := sc.generateIngress(true, perStackHostnameEnabled)
1✔
354
        if err != nil || res == nil {
2✔
355
                return res, err
1✔
356
        }
1✔
357

358
        // Synchronize annotations specified in the StackSet.
359
        res.Annotations = syncAnnotations(
1✔
360
                res.Annotations,
1✔
361
                sc.syncAnnotationsInIngress,
1✔
362
                sc.ingressAnnotationsToSync,
1✔
363
        )
1✔
364

1✔
365
        if predVal, ok := res.Annotations[IngressPredicateKey]; !ok || predVal == "" {
2✔
366
                res.Annotations = mergeLabels(
1✔
367
                        res.Annotations,
1✔
368
                        map[string]string{IngressPredicateKey: sc.trafficSegment()},
1✔
369
                )
1✔
370
        } else {
2✔
371
                res.Annotations = mergeLabels(
1✔
372
                        res.Annotations,
1✔
373
                        map[string]string{
1✔
374
                                IngressPredicateKey: sc.trafficSegment() + " && " + predVal,
1✔
375
                        },
1✔
376
                )
1✔
377
        }
1✔
378

379
        return res, nil
1✔
380
}
381

382
func (sc *StackContainer) generateIngress(segment bool, perStackHostnameEnabled bool) (
383
        *networking.Ingress,
384
        error,
385
) {
1✔
386

1✔
387
        // If Per-stack Hostnames and segments are disabled, no need to generate per stack ingresses
1✔
388
        if !perStackHostnameEnabled && !segment {
1✔
NEW
389
                return nil, nil
×
NEW
390
        }
×
391
        if !sc.HasBackendPort() || sc.ingressSpec == nil {
2✔
392
                return nil, nil
1✔
393
        }
1✔
394

395
        hostnames, err := sc.stackHostnames(sc.ingressSpec, segment)
1✔
396
        if err != nil {
1✔
397
                return nil, err
×
398
        }
×
399
        if len(hostnames) == 0 {
2✔
400
                return nil, nil
1✔
401
        }
1✔
402

403
        rules := make([]networking.IngressRule, 0, len(hostnames))
1✔
404
        for _, hostname := range hostnames {
2✔
405
                rules = append(rules, networking.IngressRule{
1✔
406
                        IngressRuleValue: networking.IngressRuleValue{
1✔
407
                                HTTP: &networking.HTTPIngressRuleValue{
1✔
408
                                        Paths: []networking.HTTPIngressPath{
1✔
409
                                                {
1✔
410
                                                        PathType: &PathTypeImplementationSpecific,
1✔
411
                                                        Path:     sc.ingressSpec.Path,
1✔
412
                                                        Backend: networking.IngressBackend{
1✔
413
                                                                Service: &networking.IngressServiceBackend{
1✔
414
                                                                        Name: sc.Name(),
1✔
415
                                                                        Port: networking.ServiceBackendPort{
1✔
416
                                                                                Name:   sc.backendPort.StrVal,
1✔
417
                                                                                Number: sc.backendPort.IntVal,
1✔
418
                                                                        },
1✔
419
                                                                },
1✔
420
                                                        },
1✔
421
                                                },
1✔
422
                                        },
1✔
423
                                },
1✔
424
                        },
1✔
425
                        Host: hostname,
1✔
426
                })
1✔
427
        }
1✔
428

429
        // sort rules by hostname for a stable order
430
        sort.Slice(rules, func(i, j int) bool {
2✔
431
                return rules[i].Host < rules[j].Host
1✔
432
        })
1✔
433

434
        result := &networking.Ingress{
1✔
435
                ObjectMeta: sc.objectMeta(segment),
1✔
436
                Spec: networking.IngressSpec{
1✔
437
                        Rules: rules,
1✔
438
                },
1✔
439
        }
1✔
440

1✔
441
        // insert annotations
1✔
442
        result.Annotations = mergeLabels(
1✔
443
                result.Annotations,
1✔
444
                sc.ingressSpec.GetAnnotations(),
1✔
445
        )
1✔
446

1✔
447
        return result, nil
1✔
448
}
449

450
func (sc *StackContainer) GenerateRouteGroup() (*rgv1.RouteGroup, error) {
1✔
451
        return sc.generateRouteGroup(false)
1✔
452
}
1✔
453

454
func (sc *StackContainer) GenerateRouteGroupSegment() (
455
        *rgv1.RouteGroup,
456
        error,
457
) {
1✔
458
        res, err := sc.generateRouteGroup(true)
1✔
459
        if err != nil || res == nil {
2✔
460
                return res, err
1✔
461
        }
1✔
462

463
        // Synchronize annotations specified in the StackSet.
464
        res.Annotations = syncAnnotations(
1✔
465
                res.Annotations,
1✔
466
                sc.syncAnnotationsInRouteGroup,
1✔
467
                sc.ingressAnnotationsToSync,
1✔
468
        )
1✔
469

1✔
470
        segmentedRoutes := []rgv1.RouteGroupRouteSpec{}
1✔
471
        for _, r := range res.Spec.Routes {
2✔
472
                r.Predicates = append(r.Predicates, sc.trafficSegment())
1✔
473
                segmentedRoutes = append(segmentedRoutes, r)
1✔
474
        }
1✔
475
        res.Spec.Routes = segmentedRoutes
1✔
476

1✔
477
        return res, nil
1✔
478
}
479

480
func (sc *StackContainer) generateRouteGroup(segment bool) (
481
        *rgv1.RouteGroup,
482
        error,
483
) {
1✔
484
        if !sc.HasBackendPort() || sc.routeGroupSpec == nil {
2✔
485
                return nil, nil
1✔
486
        }
1✔
487

488
        hostnames, err := sc.stackHostnames(sc.routeGroupSpec, segment)
1✔
489
        if err != nil {
1✔
490
                return nil, err
×
491
        }
×
492
        if len(hostnames) == 0 {
2✔
493
                return nil, nil
1✔
494
        }
1✔
495

496
        result := &rgv1.RouteGroup{
1✔
497
                ObjectMeta: sc.objectMeta(segment),
1✔
498
                Spec: rgv1.RouteGroupSpec{
1✔
499
                        Hosts: hostnames,
1✔
500
                        Backends: []rgv1.RouteGroupBackend{
1✔
501
                                {
1✔
502
                                        Name:        sc.Name(),
1✔
503
                                        Type:        rgv1.ServiceRouteGroupBackend,
1✔
504
                                        ServiceName: sc.Name(),
1✔
505
                                        ServicePort: sc.backendPort.IntValue(),
1✔
506
                                        Algorithm:   sc.routeGroupSpec.LBAlgorithm,
1✔
507
                                },
1✔
508
                        },
1✔
509
                        DefaultBackends: []rgv1.RouteGroupBackendReference{
1✔
510
                                {
1✔
511
                                        BackendName: sc.Name(),
1✔
512
                                        Weight:      100,
1✔
513
                                },
1✔
514
                        },
1✔
515
                },
1✔
516
        }
1✔
517

1✔
518
        result.Spec.Routes = sc.routeGroupSpec.Routes
1✔
519

1✔
520
        // validate not overlapping with main backend
1✔
521
        for _, backend := range sc.routeGroupSpec.AdditionalBackends {
1✔
522
                if backend.Name == sc.Name() {
×
523
                        return nil, fmt.Errorf("invalid additionalBackend '%s', overlaps with Stack name", backend.Name)
×
524
                }
×
525
                if backend.ServiceName == sc.Name() {
×
526
                        return nil, fmt.Errorf("invalid additionalBackend '%s', serviceName '%s' overlaps with Stack name", backend.Name, backend.ServiceName)
×
527
                }
×
528
                result.Spec.Backends = append(result.Spec.Backends, backend)
×
529
        }
530

531
        // sort backends to ensure have a consistent generated RouteGroup resource
532
        sort.Slice(result.Spec.Backends, func(i, j int) bool {
1✔
533
                return result.Spec.Backends[i].Name < result.Spec.Backends[j].Name
×
534
        })
×
535

536
        // insert annotations
537
        result.Annotations = mergeLabels(
1✔
538
                result.Annotations,
1✔
539
                sc.routeGroupSpec.GetAnnotations(),
1✔
540
        )
1✔
541

1✔
542
        return result, nil
1✔
543
}
544

545
func (sc *StackContainer) trafficSegment() string {
1✔
546
        return fmt.Sprintf(
1✔
547
                segmentString,
1✔
548
                sc.segmentLowerLimit,
1✔
549
                sc.segmentUpperLimit,
1✔
550
        )
1✔
551
}
1✔
552

553
func (sc *StackContainer) UpdateObjectMeta(objMeta *metav1.ObjectMeta) *metav1.ObjectMeta {
1✔
554
        metaObj := sc.resourceMeta()
1✔
555
        objMeta.OwnerReferences = metaObj.OwnerReferences
1✔
556
        objMeta.Labels = mergeLabels(metaObj.Labels, objMeta.Labels)
1✔
557
        objMeta.Annotations = mergeLabels(metaObj.Annotations, objMeta.Annotations)
1✔
558

1✔
559
        return objMeta
1✔
560
}
1✔
561

562
func (sc *StackContainer) GenerateStackStatus() *zv1.StackStatus {
1✔
563
        prescaling := zv1.PrescalingStatus{}
1✔
564
        if sc.prescalingActive {
2✔
565
                prescaling = zv1.PrescalingStatus{
1✔
566
                        Active:               sc.prescalingActive,
1✔
567
                        Replicas:             sc.prescalingReplicas,
1✔
568
                        DesiredTrafficWeight: sc.prescalingDesiredTrafficWeight,
1✔
569
                        LastTrafficIncrease:  wrapTime(sc.prescalingLastTrafficIncrease),
1✔
570
                }
1✔
571
        }
1✔
572
        return &zv1.StackStatus{
1✔
573
                ActualTrafficWeight:  sc.actualTrafficWeight,
1✔
574
                DesiredTrafficWeight: sc.desiredTrafficWeight,
1✔
575
                Replicas:             sc.createdReplicas,
1✔
576
                ReadyReplicas:        sc.readyReplicas,
1✔
577
                UpdatedReplicas:      sc.updatedReplicas,
1✔
578
                DesiredReplicas:      sc.deploymentReplicas,
1✔
579
                Prescaling:           prescaling,
1✔
580
                NoTrafficSince:       wrapTime(sc.noTrafficSince),
1✔
581
                LabelSelector:        labels.Set(sc.selector()).String(),
1✔
582
        }
1✔
583
}
584

585
func (sc *StackContainer) GeneratePlatformCredentialsSet(pcs *zv1.PCS) (*zv1.PlatformCredentialsSet, error) {
1✔
586
        if pcs.Tokens == nil {
1✔
587
                return nil, fmt.Errorf("platformCredentialsSet has no tokens")
×
588
        }
×
589

590
        metaObj := sc.resourceMeta()
1✔
591
        if _, ok := sc.Stack.Labels["application"]; !ok {
1✔
592
                return nil, fmt.Errorf("stack has no label application")
×
593
        }
×
594
        metaObj.Name = pcs.Name
1✔
595

1✔
596
        result := &zv1.PlatformCredentialsSet{
1✔
597
                ObjectMeta: metaObj,
1✔
598
                TypeMeta: metav1.TypeMeta{
1✔
599
                        Kind:       "PlatformCredentialsSet",
1✔
600
                        APIVersion: "zalando.org/v1",
1✔
601
                },
1✔
602
                Spec: zv1.PlatformCredentialsSpec{
1✔
603
                        Application:  metaObj.Labels["application"],
1✔
604
                        TokenVersion: "v2",
1✔
605
                        Tokens:       pcs.Tokens,
1✔
606
                },
1✔
607
        }
1✔
608

1✔
609
        return result, nil
1✔
610
}
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