/
failing_api_services_policy.go
53 lines (46 loc) · 1.16 KB
/
failing_api_services_policy.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
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0
package app
import (
ctlres "carvel.dev/kapp/pkg/kapp/resources"
"k8s.io/apimachinery/pkg/runtime/schema"
)
type FailingAPIServicesPolicy struct {
rs []ctlres.Resource
gvs []schema.GroupVersion
configured bool
}
func (s *FailingAPIServicesPolicy) MarkRequiredResources(rs []ctlres.Resource) {
s.rs = rs
s.configured = true
}
func (s *FailingAPIServicesPolicy) MarkRequiredGVs(gvs []schema.GroupVersion) {
s.gvs = gvs
s.configured = true
}
func (s *FailingAPIServicesPolicy) CanIgnore(groupVer schema.GroupVersion) bool {
if !s.configured {
return false
}
groupVerStr := groupVer.String()
for _, res := range s.rs {
if res.APIVersion() == groupVerStr {
return false
}
}
for _, gv := range s.gvs {
if gv.String() == groupVerStr {
return false
}
}
return true
}
func (s *FailingAPIServicesPolicy) GVs(rs1 []ctlres.Resource, rs2 []ctlres.Resource) []schema.GroupVersion {
var result []schema.GroupVersion
for _, rs := range [][]ctlres.Resource{rs1, rs2} {
for _, res := range rs {
result = append(result, res.GroupVersion())
}
}
return result
}