Newer
Older
/*
Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.gnu.org/licenses/agpl-3.0.html
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package status
import (
"k8s.io/apimachinery/pkg/runtime/schema"
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
)
// ComponentList is a generic status holder for the top level resource
// +kubebuilder:object:generate=true
type Resources struct {
// Object status array for all matching objects
Objects []ObjectStatus `json:"objects,omitempty"`
}
func Difference(original, desired *Resources) *Resources {
// diff := original.DeepCopy()
diff := &Resources{}
diffByKey := make(map[string]ObjectStatus, len(original.Objects))
desiredByKey := make(map[string]ObjectStatus, len(desired.Objects))
for _, obj := range original.Objects {
diffByKey[obj.Link] = obj
}
for _, obj := range desired.Objects {
desiredByKey[obj.Link] = obj
}
for item := range desiredByKey {
delete(diffByKey, item)
}
for _, obj := range diffByKey {
diff.Objects = append(diff.Objects, obj)
}
return diff
}
func (res *Resources) GetObjects() []ObjectStatus {
return res.Objects
}
// ObjectStatus is a generic status holder for objects
// +kubebuilder:object:generate=true
type ObjectStatus struct {
// Link to object
Link string `json:"link,omitempty"`
// Name of object
Name string `json:"name,omitempty"`
// Kind of object
Version string `json:"version,omitempty"`
// Kind of object
Kind string `json:"kind,omitempty"`
// Object group
Group string `json:"group,omitempty"`
// Status. Values: InProgress, Ready, Unknown
Status string `json:"status,omitempty"`
}
func (ost *ObjectStatus) GVK() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: ost.Group,
Version: ost.Version,
Kind: ost.Kind,
}
}
func ObjectToStatus(obj interfaces.Object) ObjectStatus {
return ObjectStatus{
Link: obj.GetSelfLink(),
Name: obj.GetName(),
Group: obj.GetObjectKind().GroupVersionKind().Group,
Version: obj.GetObjectKind().GroupVersionKind().Version,
Kind: obj.GetObjectKind().GroupVersionKind().Kind,
}
}