Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use status conditions to store build status #265

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apis/lagoon/v1beta1/lagoonbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ type LagoonBuildConditions struct {
LastTransitionTime string `json:"lastTransitionTime"`
Status corev1.ConditionStatus `json:"status"`
Type BuildStatusType `json:"type"`
// Condition string `json:"condition"`
Reason string `json:"reason"`
Message string `json:"message"`
}

func init() {
Expand Down
23 changes: 22 additions & 1 deletion apis/lagoon/v1beta1/lagoontask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,34 @@ type LagoonTaskConditions struct {
LastTransitionTime string `json:"lastTransitionTime"`
Status corev1.ConditionStatus `json:"status"`
Type TaskStatusType `json:"type"`
// Condition string `json:"condition"`
Reason string `json:"reason"`
Message string `json:"message"`
}

func init() {
SchemeBuilder.Register(&LagoonTask{}, &LagoonTaskList{})
}

// convert to string as required for environment ID for backwards compatability
func (a *LagoonTaskEnvironment) UnmarshalJSON(data []byte) error {
tmpMap := map[string]interface{}{}
json.Unmarshal(data, &tmpMap)
if value, ok := tmpMap["id"]; ok {
a.ID = fmt.Sprintf("%v", value)
}
return nil
}

// convert to string as required for project ID for backwards compatability
func (a *LagoonTaskProject) UnmarshalJSON(data []byte) error {
tmpMap := map[string]interface{}{}
json.Unmarshal(data, &tmpMap)
if value, ok := tmpMap["id"]; ok {
a.ID = fmt.Sprintf("%v", value)
}
return nil
}

// this is a custom unmarshal function that will check deployerToken and sshKey which come from Lagoon as `1|0` booleans because javascript
// this converts them from floats to bools
func (a *LagoonAdvancedTaskInfo) UnmarshalJSON(data []byte) error {
Expand Down
21 changes: 9 additions & 12 deletions apis/lagoon/v1beta2/lagoonbuild_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/uselagoon/remote-controller/internal/helpers"
"github.com/uselagoon/remote-controller/internal/metrics"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -44,7 +45,7 @@ var (
)

// BuildContainsStatus .
func BuildContainsStatus(slice []LagoonBuildConditions, s LagoonBuildConditions) bool {
func BuildContainsStatus(slice []metav1.Condition, s metav1.Condition) bool {
for _, item := range slice {
if item == s {
return true
Expand Down Expand Up @@ -363,20 +364,16 @@ func updateLagoonBuild(namespace string, jobSpec LagoonTaskSpec, lagoonBuild *La
conditions := lagoonBuild.Status.Conditions
// sort the build conditions by time so the first and last can be extracted
sort.Slice(conditions, func(i, j int) bool {
iTime, _ := time.Parse("2006-01-02T15:04:05Z", conditions[i].LastTransitionTime)
jTime, _ := time.Parse("2006-01-02T15:04:05Z", conditions[j].LastTransitionTime)
return iTime.Before(jTime)
iTime := conditions[i].LastTransitionTime
jTime := conditions[j].LastTransitionTime
return iTime.Before(&jTime)
})
// get the starting time, or fallback to default
sTime, err := time.Parse("2006-01-02T15:04:05Z", conditions[0].LastTransitionTime)
if err == nil {
msg.Meta.StartTime = sTime.Format("2006-01-02 15:04:05")
}
sTime := conditions[0].LastTransitionTime
msg.Meta.StartTime = sTime.Format("2006-01-02 15:04:05")
// get the ending time, or fallback to default
eTime, err := time.Parse("2006-01-02T15:04:05Z", conditions[len(conditions)-1].LastTransitionTime)
if err == nil {
msg.Meta.EndTime = eTime.Format("2006-01-02 15:04:05")
}
eTime := conditions[len(conditions)-1].LastTransitionTime
msg.Meta.EndTime = eTime.Format("2006-01-02 15:04:05")
}
msgBytes, err := json.Marshal(msg)
if err != nil {
Expand Down
23 changes: 9 additions & 14 deletions apis/lagoon/v1beta2/lagoonbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ package v1beta2
import (
"strings"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +kubebuilder:object:root=true
//+kubebuilder:storageversion
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=`.status.phase`,description="Status of the LagoonBuild"
// +kubebuilder:printcolumn:name="BuildStep",type="string",JSONPath=`.status.conditions[?(@.type == "BuildStep")].reason`,description="The build step of the LagoonBuild"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// LagoonBuild is the Schema for the lagoonbuilds API
type LagoonBuild struct {
Expand Down Expand Up @@ -88,18 +90,11 @@ type LagoonBuildSpec struct {

// LagoonBuildStatus defines the observed state of LagoonBuild
type LagoonBuildStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions []LagoonBuildConditions `json:"conditions,omitempty"`
Log []byte `json:"log,omitempty"`
}

// LagoonBuildConditions defines the observed conditions of build pods.
type LagoonBuildConditions struct {
LastTransitionTime string `json:"lastTransitionTime"`
Status corev1.ConditionStatus `json:"status"`
Type BuildStatusType `json:"type"`
// Condition string `json:"condition"`
// Conditions provide a standard mechanism for higher-level status reporting from a controller.
// They are an extension mechanism which allows tools and other controllers to collect summary information about
// resources without needing to understand resource-specific status details.
Conditions []metav1.Condition `json:"conditions,omitempty"`
Phase string `json:"phase,omitempty"`
}

func init() {
Expand Down
3 changes: 2 additions & 1 deletion apis/lagoon/v1beta2/lagoontask_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/uselagoon/machinery/api/schema"
"github.com/uselagoon/remote-controller/internal/helpers"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -41,7 +42,7 @@ var (
)

// TaskContainsStatus .
func TaskContainsStatus(slice []LagoonTaskConditions, s LagoonTaskConditions) bool {
func TaskContainsStatus(slice []metav1.Condition, s metav1.Condition) bool {
for _, item := range slice {
if item == s {
return true
Expand Down
22 changes: 8 additions & 14 deletions apis/lagoon/v1beta2/lagoontask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ import (
"strings"

"github.com/uselagoon/machinery/api/schema"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// +kubebuilder:object:root=true
//+kubebuilder:storageversion
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=`.status.phase`,description="Status of the LagoonTask"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// LagoonTask is the Schema for the lagoontasks API
type LagoonTask struct {
Expand Down Expand Up @@ -147,18 +148,11 @@ type LagoonTaskEnvironment struct {

// LagoonTaskStatus defines the observed state of LagoonTask
type LagoonTaskStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions []LagoonTaskConditions `json:"conditions,omitempty"`
Log []byte `json:"log,omitempty"`
}

// LagoonTaskConditions defines the observed conditions of task pods.
type LagoonTaskConditions struct {
LastTransitionTime string `json:"lastTransitionTime"`
Status corev1.ConditionStatus `json:"status"`
Type TaskStatusType `json:"type"`
// Condition string `json:"condition"`
// Conditions provide a standard mechanism for higher-level status reporting from a controller.
// They are an extension mechanism which allows tools and other controllers to collect summary information about
// resources without needing to understand resource-specific status details.
Conditions []metav1.Condition `json:"conditions,omitempty"`
Phase string `json:"phase,omitempty"`
}

func init() {
Expand Down
53 changes: 9 additions & 44 deletions apis/lagoon/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading