Skip to content
/*
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"
"k8s.libre.sh/interfaces"
)
// 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,
}
}
/*
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.libre.sh/interfaces"
)
// ApplicationStatus defines controller's the observed state of Application
// +kubebuilder:object:generate=true
type ApplicationStatus struct {
Version string `json:"version,omitempty"`
// Phase Phase `json:"phase,omitempty"`
// ObservedGeneration is the most recent generation observed. It corresponds to the
// Object's generation, which is updated on mutation by the API Server.
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"`
// Conditions represents the latest state of the object
Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,10,rep,name=conditions"`
// Components is a list of object ComponentStatus
Components map[string]ComponentStatus `json:"components,omitempty"`
Settings map[string]ComponentStatus `json:"settings,omitempty"`
// ComponentsReady: status of the components in the format ready/total
ComponentsReady string `json:"componentsReady,omitempty"`
}
func (app *ApplicationStatus) GetResources() *Resources {
resources := &Resources{}
for _, c := range app.Components {
resources.Objects = append(resources.Objects, c.GetObjects()...)
}
return resources
}
// ApplicationStatus defines controller's the observed state of Application
// +kubebuilder:object:generate=true
type ComponentStatus struct {
Name string `json:"name,omitempty"`
// Resources embeds a list of object statuses
Resources `json:",inline,omitempty"`
// ComponentsReady: status of the components in the format ready/total
ComponentsReady string `json:"componentsReady,omitempty"`
}
// Object interface must be supported by all types that want to sync an object.
// The object interface provides a mutate function and a runtime.Object that can be used in controller-runtime CreateOrUpdate
type ObjectWithStatus interface {
interfaces.Object
GetApplicationStatus() ApplicationStatus
SetApplicationStatus(conditions ApplicationStatus)
}
// +build !ignore_autogenerated
/*
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.
*/
// Code generated by controller-gen. DO NOT EDIT.
package status
import ()
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ApplicationStatus) DeepCopyInto(out *ApplicationStatus) {
*out = *in
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]Condition, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Components != nil {
in, out := &in.Components, &out.Components
*out = make(map[string]ComponentStatus, len(*in))
for key, val := range *in {
(*out)[key] = *val.DeepCopy()
}
}
if in.Settings != nil {
in, out := &in.Settings, &out.Settings
*out = make(map[string]ComponentStatus, len(*in))
for key, val := range *in {
(*out)[key] = *val.DeepCopy()
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApplicationStatus.
func (in *ApplicationStatus) DeepCopy() *ApplicationStatus {
if in == nil {
return nil
}
out := new(ApplicationStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ComponentStatus) DeepCopyInto(out *ComponentStatus) {
*out = *in
in.Resources.DeepCopyInto(&out.Resources)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComponentStatus.
func (in *ComponentStatus) DeepCopy() *ComponentStatus {
if in == nil {
return nil
}
out := new(ComponentStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Condition) DeepCopyInto(out *Condition) {
*out = *in
in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Condition.
func (in *Condition) DeepCopy() *Condition {
if in == nil {
return nil
}
out := new(Condition)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ObjectStatus) DeepCopyInto(out *ObjectStatus) {
*out = *in
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectStatus.
func (in *ObjectStatus) DeepCopy() *ObjectStatus {
if in == nil {
return nil
}
out := new(ObjectStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Resources) DeepCopyInto(out *Resources) {
*out = *in
if in.Objects != nil {
in, out := &in.Objects, &out.Objects
*out = make([]ObjectStatus, len(*in))
copy(*out, *in)
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resources.
func (in *Resources) DeepCopy() *Resources {
if in == nil {
return nil
}
out := new(Resources)
in.DeepCopyInto(out)
return out
}