Skip to content

Commit

Permalink
Improve resources status (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
assafad1 authored Oct 23, 2024
1 parent 1b23180 commit 5e68ac8
Show file tree
Hide file tree
Showing 27 changed files with 404 additions and 8,484 deletions.
132 changes: 0 additions & 132 deletions apis/coralogix/v1alpha1/alert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,116 +1082,6 @@ func expandNotification(notification Notification, webhooksNameToIds map[string]
return result, nil
}

func (in *AlertSpec) DeepEqual(actualAlert *AlertStatus) (bool, utils.Diff) {
if actualName := actualAlert.Name; actualName != in.Name {
return false, utils.Diff{
Name: "Name",
Desired: in.Name,
Actual: actualName,
}
}

if actualDescription := actualAlert.Description; actualDescription != in.Description {
return false, utils.Diff{
Name: "Description",
Desired: in.Description,
Actual: actualDescription,
}
}

if actualActive := actualAlert.Active; actualActive != in.Active {
return false, utils.Diff{
Name: "Active",
Desired: in.Active,
Actual: actualActive,
}
}

if actualSeverity := actualAlert.Severity; actualSeverity != in.Severity {
return false, utils.Diff{
Name: "Severity",
Desired: in.Severity,
Actual: actualSeverity,
}
}

if !reflect.DeepEqual(in.Labels, actualAlert.Labels) {
return false, utils.Diff{
Name: "Labels",
Desired: in.Labels,
Actual: actualAlert.Labels,
}
}

if !reflect.DeepEqual(in.ExpirationDate, actualAlert.ExpirationDate) {
return false, utils.Diff{
Name: "ExpirationDate",
Desired: utils.PointerToString(in.ExpirationDate),
Actual: utils.PointerToString(actualAlert.ExpirationDate),
}
}

if equal, diff := in.AlertType.DeepEqual(actualAlert.AlertType); !equal {
return false, utils.Diff{
Name: fmt.Sprintf("AlertType.%s", diff.Name),
Desired: diff.Desired,
Actual: diff.Actual,
}
}

notificationGroups, actualNotificationGroups := in.NotificationGroups, actualAlert.NotificationGroups
{
if equal, diff := DeepEqualNotificationGroups(notificationGroups, actualNotificationGroups); !equal {
return false, diff
}
}

if !utils.SlicesWithUniqueValuesEqual(in.PayloadFilters, actualAlert.PayloadFilters) {
return false, utils.Diff{
Name: "PayloadFilters",
Desired: in.PayloadFilters,
Actual: actualAlert.PayloadFilters,
}
}

if scheduling, actualScheduling := in.Scheduling, actualAlert.Scheduling; (scheduling == nil && actualScheduling != nil) || (scheduling != nil && actualScheduling == nil) {
return false, utils.Diff{
Name: "Scheduling",
Desired: scheduling,
Actual: actualScheduling,
}
} else if actualScheduling == nil {

} else if equal, diff := scheduling.DeepEqual(*actualScheduling); !equal {
return false, utils.Diff{
Name: fmt.Sprintf("Scheduling.%s", diff.Name),
Desired: diff.Desired,
Actual: diff.Actual,
}
}

showInInsight, actualShowInInsight := in.ShowInInsight, actualAlert.ShowInInsight
{
if showInInsight != nil {
if actualShowInInsight == nil {
return false, utils.Diff{
Name: "ShowInInsight",
Desired: *showInInsight,
Actual: actualShowInInsight,
}
} else if equal, diff := showInInsight.DeepEqual(*actualShowInInsight); !equal {
return false, utils.Diff{
Name: fmt.Sprintf("ShowInInsight.%s", diff.Name),
Desired: diff.Desired,
Actual: diff.Actual,
}
}
}
}

return true, utils.Diff{}
}

func DeepEqualNotificationGroups(notificationGroups []NotificationGroup, actualNotificationGroups []NotificationGroup) (bool, utils.Diff) {
if length, actualLength := len(notificationGroups), len(actualNotificationGroups); length != actualLength {
return false, utils.Diff{
Expand Down Expand Up @@ -3078,28 +2968,6 @@ type FlowOperator string
// AlertStatus defines the observed state of Alert
type AlertStatus struct {
ID *string `json:"id"`

Name string `json:"name,omitempty"`

Description string `json:"description,omitempty"`

Active bool `json:"active,omitempty"`

Severity AlertSeverity `json:"severity,omitempty"`

Labels map[string]string `json:"labels,omitempty"`

ExpirationDate *ExpirationDate `json:"expirationDate,omitempty"`

ShowInInsight *ShowInInsight `json:"showInInsight,omitempty"`

NotificationGroups []NotificationGroup `json:"notificationGroups,omitempty"`

PayloadFilters []string `json:"payloadFilters,omitempty"`

Scheduling *Scheduling `json:"scheduling,omitempty"`

AlertType AlertType `json:"alertType,omitempty"`
}

func NewDefaultAlertStatus() *AlertStatus {
Expand Down
104 changes: 0 additions & 104 deletions apis/coralogix/v1alpha1/outboundwebhook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@ type OutboundWebhookType struct {
AwsEventBridge *AwsEventBridge `json:"awsEventBridge,omitempty"`
}

type OutboundWebhookTypeStatus struct {
GenericWebhook *GenericWebhookStatus `json:"genericWebhook,omitempty"`

Slack *Slack `json:"slack,omitempty"`

PagerDuty *PagerDuty `json:"pagerDuty,omitempty"`

SendLog *SendLogStatus `json:"sendLog,omitempty"`

EmailGroup *EmailGroup `json:"emailGroup,omitempty"`

MicrosoftTeams *MicrosoftTeams `json:"microsoftTeams,omitempty"`

Jira *Jira `json:"jira,omitempty"`

Opsgenie *Opsgenie `json:"opsgenie,omitempty"`

Demisto *Demisto `json:"demisto,omitempty"`

AwsEventBridge *AwsEventBridge `json:"awsEventBridge,omitempty"`
}

func (in *OutboundWebhookType) appendOutgoingWebhookConfig(data *cxsdk.OutgoingWebhookInputData) (*cxsdk.OutgoingWebhookInputData, error) {
if genericWebhook := in.GenericWebhook; genericWebhook != nil {
data.Config = genericWebhook.extractGenericWebhookConfig()
Expand Down Expand Up @@ -138,55 +116,6 @@ func (in *OutboundWebhookType) appendOutgoingWebhookConfig(data *cxsdk.OutgoingW
return data, nil
}

func (in *OutboundWebhookType) DeepEqual(webhookType *OutboundWebhookTypeStatus) (bool, utils.Diff) {
if webhookType == nil {
return false, utils.Diff{
Name: "OutboundWebhookType",
Desired: utils.PointerToString(in),
Actual: nil,
}
}

equal, diff := true, utils.Diff{}
if desiredGenericWebhook, actualGenericWebhook := in.GenericWebhook, webhookType.GenericWebhook; desiredGenericWebhook != nil {
equal, diff = desiredGenericWebhook.DeepEqual(actualGenericWebhook)
} else if desiredSlack, actualSlack := in.Slack, webhookType.Slack; desiredSlack != nil {
equal, diff = desiredSlack.DeepEqual(actualSlack)
} else if desiredPagerDuty, actualPagerDuty := in.PagerDuty, webhookType.PagerDuty; desiredPagerDuty != nil {
equal, diff = desiredPagerDuty.DeepEqual(actualPagerDuty)
} else if desiredSendLog, actualSendLog := in.SendLog, webhookType.SendLog; desiredSendLog != nil {
equal, diff = desiredSendLog.DeepEqual(actualSendLog)
} else if desiredEmailGroup, actualEmailGroup := in.EmailGroup, webhookType.EmailGroup; desiredEmailGroup != nil {
equal, diff = desiredEmailGroup.DeepEqual(actualEmailGroup)
} else if desiredMicrosoftTeams, actualMicrosoftTeams := in.MicrosoftTeams, webhookType.MicrosoftTeams; desiredMicrosoftTeams != nil {
equal, diff = desiredMicrosoftTeams.DeepEqual(actualMicrosoftTeams)
} else if desiredJira, actualJira := in.Jira, webhookType.Jira; desiredJira != nil {
equal, diff = desiredJira.DeepEqual(actualJira)
} else if desiredOpsgenie, actualOpsgenie := in.Opsgenie, webhookType.Opsgenie; desiredOpsgenie != nil {
equal, diff = desiredOpsgenie.DeepEqual(actualOpsgenie)
} else if desiredDemisto, actualDemisto := in.Demisto, webhookType.Demisto; desiredDemisto != nil {
equal, diff = desiredDemisto.DeepEqual(actualDemisto)
} else if desiredAwsEventBridge, actualAwsEventBridge := in.AwsEventBridge, webhookType.AwsEventBridge; desiredAwsEventBridge != nil {
equal, diff = desiredAwsEventBridge.DeepEqual(actualAwsEventBridge)
} else {
return false, utils.Diff{
Name: "OutboundWebhookType",
Desired: utils.PointerToString(in),
Actual: utils.PointerToString(webhookType),
}
}

if !equal {
return false, utils.Diff{
Name: fmt.Sprintf("OutboundWebhookType.%s", diff.Name),
Desired: diff.Desired,
Actual: diff.Actual,
}
}

return true, utils.Diff{}
}

type GenericWebhook struct {
Url string `json:"url"`

Expand Down Expand Up @@ -767,10 +696,6 @@ type OutboundWebhookStatus struct {

// +optional
ExternalID *string `json:"externalId"`

Name string `json:"name"`

OutboundWebhookType *OutboundWebhookTypeStatus `json:"outboundWebhookType"`
}

//+kubebuilder:object:root=true
Expand Down Expand Up @@ -812,35 +737,6 @@ func (in *OutboundWebhook) ExtractUpdateOutboundWebhookRequest() (*cxsdk.UpdateO
}, nil
}

func (in *OutboundWebhookSpec) DeepEqual(status *OutboundWebhookStatus) (bool, utils.Diff) {
if status == nil {
return false, utils.Diff{
Name: "OutboundWebhookStatus",
Desired: utils.PointerToString(in),
Actual: nil,
}
}

if in.Name != status.Name {
return false, utils.Diff{
Name: "OutboundWebhookStatus.Name",
Desired: in.Name,
Actual: status.Name,
}
}

equal, diff := in.OutboundWebhookType.DeepEqual(status.OutboundWebhookType)
if !equal {
return false, utils.Diff{
Name: fmt.Sprintf("OutboundWebhookStatus.OutboundWebhookType.%s", diff.Name),
Desired: diff.Desired,
Actual: diff.Actual,
}
}

return true, utils.Diff{}
}

func (in *OutboundWebhookSpec) ExtractOutgoingWebhookInputData() (*cxsdk.OutgoingWebhookInputData, error) {
webhookData := &cxsdk.OutgoingWebhookInputData{
Name: wrapperspb.String(in.Name),
Expand Down
24 changes: 0 additions & 24 deletions apis/coralogix/v1alpha1/recordingrulegroupset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,6 @@ type RecordingRuleGroupSetSpec struct {
Groups []RecordingRuleGroup `json:"groups"`
}

func (in *RecordingRuleGroupSetSpec) DeepEqual(status RecordingRuleGroupSetStatus) (bool, utils.Diff) {
if length, actualLength := len(in.Groups), len(status.Groups); length != actualLength {
return false, utils.Diff{
Name: "Groups.Length",
Desired: length,
Actual: actualLength,
}
}

for i := range in.Groups {
if equal, diff := in.Groups[i].DeepEqual(status.Groups[i]); !equal {
return false, utils.Diff{
Name: fmt.Sprintf("Groups.%d.%s", i, diff.Name),
Desired: diff.Desired,
Actual: diff.Actual,
}
}
}

return true, utils.Diff{}
}

func (in *RecordingRuleGroupSetSpec) ExtractRecordingRuleGroups() []*cxsdk.InRuleGroup {
result := make([]*cxsdk.InRuleGroup, 0, len(in.Groups))
for _, ruleGroup := range in.Groups {
Expand Down Expand Up @@ -208,8 +186,6 @@ type RecordingRule struct {
// RecordingRuleGroupSetStatus defines the observed state of RecordingRuleGroupSet
type RecordingRuleGroupSetStatus struct {
ID *string `json:"id"`

Groups []RecordingRuleGroup `json:"groups,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Loading

0 comments on commit 5e68ac8

Please sign in to comment.