-
-
Notifications
You must be signed in to change notification settings - Fork 278
/
rs.go
51 lines (41 loc) 路 1.18 KB
/
rs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Popeye
package lint
import (
"context"
"github.com/derailed/popeye/internal"
"github.com/derailed/popeye/internal/client"
"github.com/derailed/popeye/internal/db"
"github.com/derailed/popeye/internal/issues"
appsv1 "k8s.io/api/apps/v1"
)
// ReplicaSet tracks ReplicaSet sanitization.
type ReplicaSet struct {
*issues.Collector
db *db.DB
}
// NewReplicaSet returns a new instance.
func NewReplicaSet(co *issues.Collector, db *db.DB) *ReplicaSet {
return &ReplicaSet{
Collector: co,
db: db,
}
}
// Lint cleanse the resource.
func (s *ReplicaSet) Lint(ctx context.Context) error {
txn, it := s.db.MustITFor(internal.Glossary[internal.RS])
defer txn.Abort()
for o := it.Next(); o != nil; o = it.Next() {
rs := o.(*appsv1.ReplicaSet)
fqn := client.FQN(rs.Namespace, rs.Name)
s.InitOutcome(fqn)
ctx = internal.WithSpec(ctx, SpecFor(fqn, rs))
s.checkHealth(ctx, rs)
}
return nil
}
func (s *ReplicaSet) checkHealth(ctx context.Context, rs *appsv1.ReplicaSet) {
if rs.Spec.Replicas != nil && *rs.Spec.Replicas != rs.Status.ReadyReplicas {
s.AddCode(ctx, 1120, *rs.Spec.Replicas, rs.Status.ReadyReplicas)
}
}