@@ -16,6 +16,10 @@ limitations under the License.
16
16
17
17
package config
18
18
19
+ import (
20
+ "strings"
21
+ )
22
+
19
23
// Scaffolding versions
20
24
const (
21
25
Version1 = "1"
@@ -51,29 +55,8 @@ func (config Config) IsV2() bool {
51
55
return config .Version == Version2
52
56
}
53
57
54
- // ResourceGroups returns unique groups of scaffolded resources in the project
55
- func (config Config ) ResourceGroups () []string {
56
- groupSet := map [string ]struct {}{}
57
- for _ , r := range config .Resources {
58
- groupSet [r .Group ] = struct {}{}
59
- }
60
-
61
- groups := make ([]string , 0 , len (groupSet ))
62
- for g := range groupSet {
63
- groups = append (groups , g )
64
- }
65
-
66
- return groups
67
- }
68
-
69
58
// HasResource returns true if API resource is already tracked
70
- // NOTE: this works only for v2, since in v1 resources are not tracked
71
59
func (config Config ) HasResource (target GVK ) bool {
72
- // Short-circuit v1
73
- if config .Version == Version1 {
74
- return false
75
- }
76
-
77
60
// Return true if the target resource is found in the tracked resources
78
61
for _ , r := range config .Resources {
79
62
if r .isEqualTo (target ) {
@@ -87,10 +70,10 @@ func (config Config) HasResource(target GVK) bool {
87
70
88
71
// AddResource appends the provided resource to the tracked ones
89
72
// It returns if the configuration was modified
90
- // NOTE: this works only for v2, since in v1 resources are not tracked
73
+ // NOTE: in v1 resources are not tracked, so we return false
91
74
func (config * Config ) AddResource (gvk GVK ) bool {
92
75
// Short-circuit v1
93
- if config .Version == Version1 {
76
+ if config .IsV1 () {
94
77
return false
95
78
}
96
79
@@ -104,6 +87,19 @@ func (config *Config) AddResource(gvk GVK) bool {
104
87
return true
105
88
}
106
89
90
+ // HasGroup returns true if group is already tracked
91
+ func (config Config ) HasGroup (group string ) bool {
92
+ // Return true if the target group is found in the tracked resources
93
+ for _ , r := range config .Resources {
94
+ if strings .EqualFold (group , r .Group ) {
95
+ return true
96
+ }
97
+ }
98
+
99
+ // Return false otherwise
100
+ return false
101
+ }
102
+
107
103
// GVK contains information about scaffolded resources
108
104
type GVK struct {
109
105
Group string `json:"group,omitempty"`
0 commit comments