/
pv.go
57 lines (48 loc) 路 1.27 KB
/
pv.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
52
53
54
55
56
57
// 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"
v1 "k8s.io/api/core/v1"
)
type (
// PersistentVolume represents a PersistentVolume linter.
PersistentVolume struct {
*issues.Collector
db *db.DB
}
)
// NewPersistentVolume returns a new instance.
func NewPersistentVolume(co *issues.Collector, db *db.DB) *PersistentVolume {
return &PersistentVolume{
Collector: co,
db: db,
}
}
// Lint cleanse the resource.
func (s *PersistentVolume) Lint(ctx context.Context) error {
txn, it := s.db.MustITFor(internal.Glossary[internal.PV])
defer txn.Abort()
for o := it.Next(); o != nil; o = it.Next() {
pv := o.(*v1.PersistentVolume)
fqn := client.FQN(pv.Namespace, pv.Name)
s.InitOutcome(fqn)
ctx = internal.WithSpec(ctx, SpecFor(fqn, pv))
s.checkBound(ctx, pv.Status.Phase)
}
return nil
}
func (s *PersistentVolume) checkBound(ctx context.Context, phase v1.PersistentVolumePhase) {
switch phase {
case v1.VolumeAvailable:
s.AddCode(ctx, 1000)
case v1.VolumePending:
s.AddCode(ctx, 1001)
case v1.VolumeFailed:
s.AddCode(ctx, 1002)
}
}