Skip to content
status.go 2.59 KiB
Newer Older
Timothee Gosselin's avatar
Timothee Gosselin committed
/*

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 (
Timothee Gosselin's avatar
Timothee Gosselin committed
	"k8s.libre.sh/controller-utils/interfaces"
Timothee Gosselin's avatar
Timothee Gosselin committed
)

// ApplicationStatus defines controller's the observed state of Application
Timothee Gosselin's avatar
Timothee Gosselin committed
// +kubebuilder:object:generate=true
Timothee Gosselin's avatar
Timothee Gosselin committed
type ApplicationStatus struct {
	Version string `json:"version,omitempty"`
	// Phase   Phase  `json:"phase,omitempty"`
Timothee Gosselin's avatar
Timothee Gosselin committed
	// 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"`
Timothee Gosselin's avatar
Timothee Gosselin committed
	// Components is a list of object ComponentStatus
	Components map[string]ComponentStatus `json:"components,omitempty"`
Timothee Gosselin's avatar
Timothee Gosselin committed
	Settings   map[string]ComponentStatus `json:"settings,omitempty"`
Timothee Gosselin's avatar
Timothee Gosselin committed
	// ComponentsReady: status of the components in the format ready/total
Timothee Gosselin's avatar
Timothee Gosselin committed
	ComponentsReady string    `json:"componentsReady,omitempty"`
	Watched         Resources `json:"watched,omitempty"`
Timothee Gosselin's avatar
Timothee Gosselin committed
}

Timothee Gosselin's avatar
Timothee Gosselin committed
func (app *ApplicationStatus) GetResources() *Resources {
	resources := &Resources{}

	for _, c := range app.Components {
		resources.Objects = append(resources.Objects, c.GetObjects()...)
	}

	return resources
}

Timothee Gosselin's avatar
Timothee Gosselin committed
// ApplicationStatus defines controller's the observed state of Application
Timothee Gosselin's avatar
Timothee Gosselin committed
// +kubebuilder:object:generate=true
Timothee Gosselin's avatar
Timothee Gosselin committed
type ComponentStatus struct {
	Name string `json:"name,omitempty"`
Timothee Gosselin's avatar
Timothee Gosselin committed
	// Resources embeds a list of object statuses
Timothee Gosselin's avatar
Timothee Gosselin committed
	Resources `json:",inline"`
Timothee Gosselin's avatar
Timothee Gosselin committed
	// 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)
}