2 Copyright The Helm Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 package statuscheck // import "helm.sh/helm/v3/pkg/kube"
19 import "k8s.io/cli-runtime/pkg/resource"
21 // ResourceList provides convenience methods for comparing collections of Infos.
22 type ResourceList []*resource.Info
24 // Append adds an Info to the Result.
25 func (r *ResourceList) Append(val *resource.Info) {
29 // Visit implements resource.Visitor.
30 func (r ResourceList) Visit(fn resource.VisitorFunc) error {
32 if err := fn(i, nil); err != nil {
39 // Filter returns a new Result with Infos that satisfy the predicate fn.
40 func (r ResourceList) Filter(fn func(*resource.Info) bool) ResourceList {
41 var result ResourceList
50 // Get returns the Info from the result that matches the name and kind.
51 func (r ResourceList) Get(info *resource.Info) *resource.Info {
53 if isMatchingInfo(i, info) {
60 // Contains checks to see if an object exists.
61 func (r ResourceList) Contains(info *resource.Info) bool {
63 if isMatchingInfo(i, info) {
70 // Difference will return a new Result with objects not contained in rs.
71 func (r ResourceList) Difference(rs ResourceList) ResourceList {
72 return r.Filter(func(info *resource.Info) bool {
73 return !rs.Contains(info)
77 // Intersect will return a new Result with objects contained in both Results.
78 func (r ResourceList) Intersect(rs ResourceList) ResourceList {
79 return r.Filter(rs.Contains)
82 // isMatchingInfo returns true if infos match on Name and GroupVersionKind.
83 func isMatchingInfo(a, b *resource.Info) bool {
84 return a.Name == b.Name && a.Namespace == b.Namespace && a.Mapping.GroupVersionKind.Kind == b.Mapping.GroupVersionKind.Kind