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

Maintenance Events resource was transfered to the APIv2 #555

Merged
merged 1 commit into from
Sep 15, 2023

Conversation

testisnullus
Copy link
Collaborator

@testisnullus testisnullus commented Sep 13, 2023

Blocked until the https://instaclustr.atlassian.net/browse/INS-25547 issue is resolved

@testisnullus testisnullus added the refactor Code improvements or refactorings label Sep 13, 2023
@testisnullus testisnullus self-assigned this Sep 13, 2023
@testisnullus testisnullus changed the title Maintenance Events resource was transfered to APIv2 [WIP] Maintenance Events resource was transfered to APIv2 Sep 13, 2023
@testisnullus testisnullus force-pushed the maintenance-events-to-apiv2 branch 3 times, most recently from 7f8e3d1 to 518b189 Compare September 13, 2023 10:52
@testisnullus testisnullus changed the title [WIP] Maintenance Events resource was transfered to APIv2 [WIP] Maintenance Events resource was transfered to the APIv2 Sep 13, 2023
@testisnullus testisnullus added the blocked Some events are blocking the issue or pull request label Sep 13, 2023
@testisnullus testisnullus force-pushed the maintenance-events-to-apiv2 branch from 518b189 to 2cc9c6c Compare September 14, 2023 16:33
@testisnullus testisnullus changed the title [WIP] Maintenance Events resource was transfered to the APIv2 Maintenance Events resource was transfered to the APIv2 Sep 14, 2023
@testisnullus testisnullus removed the blocked Some events are blocking the issue or pull request label Sep 14, 2023
@testisnullus testisnullus force-pushed the maintenance-events-to-apiv2 branch from 2cc9c6c to 4400f48 Compare September 14, 2023 16:36
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RescheduledEvent -> CurrentRescheduledEvent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


type MaintenanceEventReschedule struct {
ScheduledStartTime string `json:"scheduledStartTime"`
MaintenanceEventId string `json:"maintenanceEventId"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaintenanceEventId -> MaintenanceEventID

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 78 to 83
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)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the last part of the 79 line:

; err != nil || !dateValid

so the validation.ValidateISODate function may not have an error, and still dateValid variable may not be valid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the customer provides scheduledStartTime in an invalid format, we will return the error message

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why then check for !dateValid, if there is always an error returned by invalid format?

return true
}

func areClusteredMaintenanceEventStatusEqual(a, b *clusterresource.MaintenanceEventStatus) bool {
return a.ID == b.ID &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a.ID == b.ID shouldn't be used in comparing, instead, use this condition to actually be sure that this is the same maintenance event and after only perform equality func.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will fix

@@ -509,6 +542,28 @@ func (c *Cluster) CloudProviderSettingsFromInstAPI(iDC models.DataCentre) (setti
return
}

func (c *Cluster) CloudProviderSettingsFromInstAPIv1(iProviders []*models.ClusterProviderV1) (accountName string, settings []*CloudProviderSettings) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, it seems that I've accidentally added this method when resolving conflicts

@@ -3,7 +3,7 @@ kind: Cassandra
metadata:
name: cassandra-cluster
spec:
name: "username-Cassandra"
name: "danylo-Cassandra"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave it as it was

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 129 to 148
patch := me.NewPatch()
me.Status.RescheduledEvent = *meReschedule
err = r.Status().Patch(ctx, me, patch)
if err != nil {
l.Error(err, "Cannot get Maintenance Events resource",
"resource", me,
l.Error(err,
"Cannot patch Maintenance Event status",
"Maintenance Event ID", me.Status.RescheduledEvent.MaintenanceEventId,
)

return err
r.EventRecorder.Eventf(
me, models.Warning, models.PatchFailed,
"Resource status patch is failed. Reason: %v",
err,
)
return models.ReconcileRequeue, nil
}

var updated bool
patch := me.NewPatch()
instMEventsStatuses, err := r.API.GetMaintenanceEventsStatuses(me.Spec.ClusterID)
patch = me.NewPatch()
me.Status.RescheduledEvent.MaintenanceEventId = ""
me.Status.RescheduledEvent.ScheduledStartTime = ""
err = r.Status().Patch(ctx, me, patch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point in filling out the Status and then removing it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point, will fix

if !c.Status.AreMaintenanceEventStatusesEqual(iMEStatuses) {
patch := c.NewPatch()
c.Status.MaintenanceEvents = iMEStatuses
err = r.Status().Patch(context.TODO(), c, patch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use ctx from the func param

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed for all similar cases

Comment on lines 20 to 22
"encoding/json"
"fmt"
clusterresourcesv1beta1 "github.com/instaclustr/operator/apis/clusterresources/v1beta1"
"github.com/instaclustr/operator/pkg/instaclustr"
"sort"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

busted 🐾 🐾 🐾

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 164 to 169
func fetchMaintenanceEventStatuses(
api instaclustr.API,
clusterID string,
) ([]*clusterresourcesv1beta1.ClusteredMaintenanceEventStatus,
error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making it as a method for instaclustr.API client?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds pretty logical, will move to the client

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Upcoming []*MaintenanceEventStatus `json:"Upcoming"`
Upcoming []*MaintenanceEventStatus `json:"upcoming"`

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix

if !c.Status.AreMaintenanceEventStatusesEqual(iMEStatuses) {
patch := c.NewPatch()
c.Status.MaintenanceEvents = iMEStatuses
err = r.Status().Patch(context.TODO(), c, patch)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the provided ctx from the func params. Please do it in all such cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@testisnullus testisnullus force-pushed the maintenance-events-to-apiv2 branch 2 times, most recently from bcce9bb to b3f2910 Compare September 15, 2023 10:13
@testisnullus testisnullus force-pushed the maintenance-events-to-apiv2 branch from b3f2910 to d2ec9ae Compare September 15, 2023 10:19
@testisnullus testisnullus force-pushed the maintenance-events-to-apiv2 branch from d2ec9ae to b42cb94 Compare September 15, 2023 11:32
@testisnullus testisnullus force-pushed the maintenance-events-to-apiv2 branch from b42cb94 to 750f126 Compare September 15, 2023 12:19
@testisnullus testisnullus merged commit e5603dd into main Sep 15, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code improvements or refactorings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants