Skip to content

Commit

Permalink
Improve resources status
Browse files Browse the repository at this point in the history
  • Loading branch information
assafad1 committed Oct 21, 2024
1 parent cb87680 commit e8d162b
Show file tree
Hide file tree
Showing 28 changed files with 405 additions and 8,485 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
deploy: manifests kustomize install ## Deploy controller to the K8s cluster specified in ~/.kube/config.
# Step 1: Set the image in the manager deployment
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}

Expand Down
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 e8d162b

Please sign in to comment.