Skip to content

Commit

Permalink
Maintenance Events resource was transfered to APIv2
Browse files Browse the repository at this point in the history
  • Loading branch information
testisnullus committed Sep 14, 2023
1 parent 8a6906b commit 2cc9c6c
Show file tree
Hide file tree
Showing 31 changed files with 1,284 additions and 685 deletions.
60 changes: 18 additions & 42 deletions apis/clusterresources/v1beta1/maintenanceevents_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,24 @@ limitations under the License.
package v1beta1

import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/instaclustr/operator/pkg/validation"
)

type MaintenanceEventRescheduleSpec struct {
ScheduledStartTime string `json:"scheduledStartTime"`
ScheduleID string `json:"scheduleId"`
}

// MaintenanceEventsSpec defines the desired state of MaintenanceEvents
type MaintenanceEventsSpec struct {
ClusterID string `json:"clusterId"`
MaintenanceEventsReschedules []*MaintenanceEventRescheduleSpec `json:"maintenanceEventsReschedule,omitempty"`
ClusterID string `json:"clusterId"`
MaintenanceEventsReschedules []*MaintenanceEventReschedule `json:"maintenanceEventsReschedule"`
}

// MaintenanceEventsStatus defines the observed state of MaintenanceEvents
type MaintenanceEventsStatus struct {
EventsStatuses []*MaintenanceEventStatus `json:"eventsStatuses,omitempty"`
RescheduledEvent MaintenanceEventReschedule `json:"rescheduled"`
}

type MaintenanceEventReschedule struct {
ScheduledStartTime string `json:"scheduledStartTime"`
MaintenanceEventId string `json:"maintenanceEventId"`
}

type MaintenanceEventStatus struct {
Expand All @@ -47,7 +44,16 @@ type MaintenanceEventStatus struct {
ScheduledEndTime string `json:"scheduledEndTime,omitempty"`
ScheduledStartTimeMin string `json:"scheduledStartTimeMin,omitempty"`
ScheduledStartTimeMax string `json:"scheduledStartTimeMax,omitempty"`
IsFinalized bool `json:"isFinalized,omitempty"`
IsFinalized bool `json:"isFinalized"`
StartTime string `json:"startTime,omitempty"`
EndTime string `json:"endTime,omitempty"`
Outcome string `json:"outcome,omitempty"`
}

type ClusteredMaintenanceEventStatus struct {
InProgress []*MaintenanceEventStatus `json:"inProgress"`
Past []*MaintenanceEventStatus `json:"past"`
Upcoming []*MaintenanceEventStatus `json:"Upcoming"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -80,36 +86,6 @@ func (me *MaintenanceEvents) NewPatch() client.Patch {
return client.MergeFrom(old)
}

func (me *MaintenanceEvents) AreMEventsStatusesEqual(instMEventsStatuses []*MaintenanceEventStatus) bool {
if len(instMEventsStatuses) != len(me.Status.EventsStatuses) {
return false
}

for _, instMEvent := range instMEventsStatuses {
for _, k8sMEvent := range me.Status.EventsStatuses {
if instMEvent.ID == k8sMEvent.ID {
if *instMEvent != *k8sMEvent {
return false
}

break
}
}
}

return true
}

func (mes *MaintenanceEventsSpec) ValidateMaintenanceEventsReschedules() error {
for _, event := range mes.MaintenanceEventsReschedules {
if dateValid, err := validation.ValidateISODate(event.ScheduledStartTime); err != nil || !dateValid {
return fmt.Errorf("scheduledStartTime must be provided in an ISO-8601 formatted UTC string: %v", err)
}
}

return nil
}

func init() {
SchemeBuilder.Register(&MaintenanceEvents{}, &MaintenanceEventsList{})
}
15 changes: 13 additions & 2 deletions apis/clusterresources/v1beta1/maintenanceevents_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1beta1

import (
"fmt"
"github.com/instaclustr/operator/pkg/validation"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -42,7 +43,7 @@ var _ webhook.Validator = &MaintenanceEvents{}
func (r *MaintenanceEvents) ValidateCreate() error {
maintenanceeventslog.Info("validate create", "name", r.Name)

if err := r.Spec.ValidateMaintenanceEventsReschedules(); err != nil {
if err := r.ValidateMaintenanceEventsReschedules(); err != nil {
return fmt.Errorf("maintenance events reschedules validation failed: %v", err)
}

Expand All @@ -57,7 +58,7 @@ func (r *MaintenanceEvents) ValidateUpdate(old runtime.Object) error {
return nil
}

if err := r.Spec.ValidateMaintenanceEventsReschedules(); err != nil {
if err := r.ValidateMaintenanceEventsReschedules(); err != nil {
return fmt.Errorf("maintenance events reschedules validation failed: %v", err)
}

Expand All @@ -71,3 +72,13 @@ func (r *MaintenanceEvents) ValidateDelete() error {
// TODO(user): fill in your validation logic upon object deletion.
return nil
}

func (r *MaintenanceEvents) ValidateMaintenanceEventsReschedules() error {
for _, event := range r.Spec.MaintenanceEventsReschedules {
if dateValid, err := validation.ValidateISODate(event.ScheduledStartTime); err != nil || !dateValid {
return fmt.Errorf("scheduledStartTime must be provided in an ISO-8601 formatted UTC string: %v", err)
}
}

return nil
}
74 changes: 56 additions & 18 deletions apis/clusterresources/v1beta1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 2cc9c6c

Please sign in to comment.