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

zalando-incubator / stackset-controller / 8649011694

11 Apr 2024 03:04PM UTC coverage: 49.355% (-1.0%) from 50.373%
8649011694

Pull #593

github

linki
some labels
Pull Request #593: [2/3] Add Inline Solution for ConfigMaps

0 of 114 new or added lines in 3 files covered. (0.0%)

2 existing lines in 1 file now uncovered.

2831 of 5736 relevant lines covered (49.35%)

0.55 hits per line

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

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

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

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

24
const (
25
        apiVersionAppsV1 = "apps/v1"
26
        kindDeployment   = "Deployment"
27

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

142
        return servicePorts, nil
1✔
143
}
144

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

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

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

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

182
        var updatedReplicas *int32
1✔
183

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

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

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

205
        embeddedCopy := stack.Spec.StackSpec.PodTemplate.EmbeddedObjectMeta.DeepCopy()
1✔
206

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

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

232
func (sc *StackContainer) GenerateHPA() (
233
        *autoscaling.HorizontalPodAutoscaler,
234
        error,
235
) {
1✔
236
        autoscalerSpec := sc.Stack.Spec.StackSpec.Autoscaler
1✔
237
        trafficWeight := sc.actualTrafficWeight
1✔
238

1✔
239
        if autoscalerSpec == nil {
1✔
240
                return nil, nil
×
241
        }
×
242

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

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

1✔
262
        result.Spec.MinReplicas = autoscalerSpec.MinReplicas
1✔
263
        result.Spec.MaxReplicas = autoscalerSpec.MaxReplicas
1✔
264

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

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

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

286
        return result, nil
1✔
287
}
288

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

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

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

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

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

347
func (sc *StackContainer) GenerateIngress() (*networking.Ingress, error) {
1✔
348
        return sc.generateIngress(false)
1✔
349
}
1✔
350

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

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

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

381
        return res, nil
1✔
382
}
383

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

1✔
389
        if !sc.HasBackendPort() || sc.ingressSpec == nil {
2✔
390
                return nil, nil
1✔
391
        }
1✔
392

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

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

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

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

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

1✔
445
        return result, nil
1✔
446
}
447

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

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

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

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

1✔
475
        return res, nil
1✔
476
}
477

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

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

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

1✔
516
        result.Spec.Routes = sc.routeGroupSpec.Routes
1✔
517

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

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

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

1✔
540
        return result, nil
1✔
541
}
542

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

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

1✔
557
        return objMeta
1✔
558
}
1✔
559

NEW
560
func (sc *StackContainer) GenerateConfigMaps(ctx context.Context, client clientset.Interface) ([]*v1.ConfigMap, error) {
×
NEW
561
        result := []*v1.ConfigMap{}
×
NEW
562

×
NEW
563
        for _, configResource := range sc.Stack.Spec.ConfigurationResources {
×
NEW
564
                if configResource.IsConfigMap() {
×
NEW
565
                        metaObj := sc.resourceMeta()
×
NEW
566
                        metaObj.Name = metaObj.Name + "-" + configResource.GetName()
×
NEW
567
                        metaObj.OwnerReferences = []metav1.OwnerReference{ // maybe that should be metaObj.OwnerReferences instead
×
NEW
568
                                {
×
NEW
569
                                        APIVersion: APIVersion,
×
NEW
570
                                        Kind:       KindStack,
×
NEW
571
                                        Name:       sc.Name(),
×
NEW
572
                                        UID:        sc.Stack.UID,
×
NEW
573
                                },
×
NEW
574
                        }
×
NEW
575

×
NEW
576
                        base := &v1.ConfigMap{
×
NEW
577
                                ObjectMeta: metaObj,
×
NEW
578
                                Data:       configResource.ConfigMap.Data,
×
NEW
579
                        }
×
NEW
580

×
NEW
581
                        result = append(result, base)
×
NEW
582
                }
×
583

NEW
584
                if configResource.IsConfigMapRef() {
×
NEW
585
                        configMap, err := client.CoreV1().ConfigMaps(sc.Namespace()).Get(ctx, configResource.GetName(), metav1.GetOptions{})
×
NEW
586
                        if err != nil {
×
NEW
587
                                return nil, err
×
NEW
588
                        }
×
589

NEW
590
                        metaObj := sc.resourceMeta()
×
NEW
591

×
NEW
592
                        configMap.ObjectMeta.OwnerReferences = metaObj.OwnerReferences
×
NEW
593
                        configMap.ObjectMeta.Labels = mergeLabels(metaObj.Labels, configMap.ObjectMeta.Labels)
×
NEW
594
                        configMap.ObjectMeta.Annotations = mergeLabels(metaObj.Annotations, configMap.ObjectMeta.Annotations)
×
NEW
595

×
NEW
596
                        result = append(result, configMap)
×
597
                }
598
        }
599

NEW
600
        return result, nil
×
601
}
602

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