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 15, 2023
1 parent 7c0608c commit b3f2910
Show file tree
Hide file tree
Showing 30 changed files with 1,229 additions and 672 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"`
CurrentRescheduledEvent MaintenanceEventReschedule `json:"currentRescheduledEvent"`
}

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{})
}
16 changes: 14 additions & 2 deletions apis/clusterresources/v1beta1/maintenanceevents_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"

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

var maintenanceeventslog = logf.Log.WithName("maintenanceevents-resource")
Expand All @@ -42,7 +44,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 +59,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 +73,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 b3f2910

Please sign in to comment.