diff --git a/pkg/controller/glue/trigger/setup.go b/pkg/controller/glue/trigger/setup.go index 9075f52abe..53c854669a 100644 --- a/pkg/controller/glue/trigger/setup.go +++ b/pkg/controller/glue/trigger/setup.go @@ -255,8 +255,9 @@ func createPatch(currentParams *svcapitypes.TriggerParameters, resp *svcsdk.GetT externalConfig := &svcapitypes.TriggerParameters{} externalConfig.Schedule = resp.Trigger.Schedule if resp.Trigger.Predicate != nil { + externalConfig.Predicate = &svcapitypes.Predicate{} if resp.Trigger.Predicate.Conditions != nil { - externalConfig.Predicate.Conditions = make([]*svcapitypes.Condition, 0, len(resp.Trigger.Predicate.Conditions)) + externalConfig.Predicate = &svcapitypes.Predicate{Conditions: make([]*svcapitypes.Condition, 0, len(resp.Trigger.Predicate.Conditions))} for _, respCondition := range resp.Trigger.Predicate.Conditions { curCondition := &svcapitypes.Condition{} if respCondition.CrawlState != nil { @@ -277,8 +278,8 @@ func createPatch(currentParams *svcapitypes.TriggerParameters, resp *svcsdk.GetT externalConfig.Predicate.Conditions = append(externalConfig.Predicate.Conditions, curCondition) } } - if resp.Trigger.Predicate.Logical != nil { - externalConfig.Predicate.Logical = resp.Trigger.Predicate.Logical + if resp.Trigger.Predicate != nil && resp.Trigger.Predicate.Logical != nil { + externalConfig.Predicate = &svcapitypes.Predicate{Logical: resp.Trigger.Predicate.Logical} } } if resp.Trigger.Actions != nil { diff --git a/pkg/controller/glue/trigger/setup_test.go b/pkg/controller/glue/trigger/setup_test.go index 4fcefab12e..b4193d9463 100644 --- a/pkg/controller/glue/trigger/setup_test.go +++ b/pkg/controller/glue/trigger/setup_test.go @@ -28,36 +28,46 @@ import ( svcapitypes "github.com/crossplane-contrib/provider-aws/apis/glue/v1alpha1" ) -const ( - triggerName = "triggerName" - region = "eu-central-2" - actionsJobName = "jobName" - actionJobTimeout int64 = 1 - description = "Trigger for Glue" - schedule = "cron(*/5 * * * ? *)" - startOnCreation = true - triggerType = "SCHEDULED" -) - type args struct { trigger *svcapitypes.Trigger getTriggerOutput *svcsdk.GetTriggerOutput } func TestIsUpToDate(t *testing.T) { - actionsJobName := actionsJobName - actionJobTimeout := actionJobTimeout - description := description - schedule := schedule - startOnCreation := startOnCreation - triggerName := triggerName - triggerType := triggerType - + region := "eu-central-2" + triggerName := "TriggerName" + actionsJobName1 := "JobName1" + actionsJobName2 := "jobName2" + actionArgumentValue1 := "argumentValue" + eventBatchingConditionBatchSize := int64(3) + newEventBatchingConditionBatchSize := int64(4) + eventBatchingConditionBatchWindow := int64(15) + newEventBatchingConditionBatchWindow := int64(20) + actionJobTimeout := int64(1) newActionJobTimeout := int64(2) + description := "Trigger for Glue" newDescription := "New Description" + triggerType := "SCHEDULED" newTriggerType := "ON_DEMAND" + schedule := "cron(*/5 * * * ? *)" newSchedule := "cron(*/3 * * * ? *)" + startOnCreation := true newStartOnCreation := false + notificationPropertyNotifyDelayAfter := int64(1) + newNotificationPropertyNotifyDelayAfter := int64(2) + predicateConditionCrawlerStateReady := "READY" + predicateConditionCrawlerStateRunning := "RUNNING" + predicateConditionCrawlerName := "CrawlerName" + newPredicateConditionCrawlerName := "NewCrawlerName" + predicateConditionJobName := "JobName" + newPredicateConditionJobName := "NewJobName" + predicateConditionLogicalOperator := "EQUALS" + predicateConditionStateSucceeded := "SUCCEEDED" + predicateConditionStateStopped := "STOPPED" + predicateLogical := "AND" + newPredicateLogical := "ANY" + workflowName := "WorkflowName" + newWorkflowName := "NewWorkflowName" type want struct { result bool @@ -81,7 +91,7 @@ func TestIsUpToDate(t *testing.T) { Region: region, Actions: []*svcapitypes.Action{ { - JobName: &actionsJobName, + JobName: &actionsJobName1, Timeout: &actionJobTimeout, }, }, @@ -97,7 +107,7 @@ func TestIsUpToDate(t *testing.T) { Name: &triggerName, Actions: []*svcsdk.Action{ { - JobName: &actionsJobName, + JobName: &actionsJobName1, Timeout: &actionJobTimeout, }, }, @@ -123,17 +133,66 @@ func TestIsUpToDate(t *testing.T) { }, Spec: svcapitypes.TriggerSpec{ ForProvider: svcapitypes.TriggerParameters{ - Region: region, + Schedule: &newSchedule, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Schedule: &schedule, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "DescriptionChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + Description: &newDescription, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Description: &description, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "ActionTimeoutChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ Actions: []*svcapitypes.Action{ { - JobName: &actionsJobName, - Timeout: &actionJobTimeout, + JobName: &actionsJobName1, + Timeout: &newActionJobTimeout, }, }, - Description: &description, - Schedule: &newSchedule, - StartOnCreation: &startOnCreation, - TriggerType: &triggerType, }, }, }, @@ -142,13 +201,10 @@ func TestIsUpToDate(t *testing.T) { Name: &triggerName, Actions: []*svcsdk.Action{ { - JobName: &actionsJobName, + JobName: &actionsJobName1, Timeout: &actionJobTimeout, }, }, - Description: &description, - Schedule: &schedule, - Type: &triggerType, }, }, }, @@ -157,7 +213,7 @@ func TestIsUpToDate(t *testing.T) { err: nil, }, }, - "DescriptionChanged": { + "ActionArgumentsChanged": { args: args{ trigger: &svcapitypes.Trigger{ ObjectMeta: metav1.ObjectMeta{ @@ -168,17 +224,15 @@ func TestIsUpToDate(t *testing.T) { }, Spec: svcapitypes.TriggerSpec{ ForProvider: svcapitypes.TriggerParameters{ - Region: region, Actions: []*svcapitypes.Action{ { - JobName: &actionsJobName, - Timeout: &actionJobTimeout, + JobName: &actionsJobName1, + Arguments: map[string]*string{ + "--foo": &actionArgumentValue1, + "--bar": &actionArgumentValue1, + }, }, }, - Description: &newDescription, - Schedule: &schedule, - StartOnCreation: &startOnCreation, - TriggerType: &triggerType, }, }, }, @@ -187,13 +241,12 @@ func TestIsUpToDate(t *testing.T) { Name: &triggerName, Actions: []*svcsdk.Action{ { - JobName: &actionsJobName, - Timeout: &actionJobTimeout, + JobName: &actionsJobName1, + Arguments: map[string]*string{ + "--foo": &actionArgumentValue1, + }, }, }, - Description: &description, - Schedule: &schedule, - Type: &triggerType, }, }, }, @@ -202,7 +255,48 @@ func TestIsUpToDate(t *testing.T) { err: nil, }, }, - "ActionChanged": { + "ActionNotificationPropertyNotifyDelayAfterChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + Actions: []*svcapitypes.Action{ + { + JobName: &actionsJobName1, + NotificationProperty: &svcapitypes.NotificationProperty{ + NotifyDelayAfter: ¬ificationPropertyNotifyDelayAfter, + }, + }, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Actions: []*svcsdk.Action{ + { + JobName: &actionsJobName1, + NotificationProperty: &svcsdk.NotificationProperty{ + NotifyDelayAfter: &newNotificationPropertyNotifyDelayAfter, + }, + }, + }, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "ActionAdded": { args: args{ trigger: &svcapitypes.Trigger{ ObjectMeta: metav1.ObjectMeta{ @@ -213,17 +307,16 @@ func TestIsUpToDate(t *testing.T) { }, Spec: svcapitypes.TriggerSpec{ ForProvider: svcapitypes.TriggerParameters{ - Region: region, Actions: []*svcapitypes.Action{ { - JobName: &actionsJobName, + JobName: &actionsJobName1, + Timeout: &actionJobTimeout, + }, + { + JobName: &actionsJobName2, Timeout: &newActionJobTimeout, }, }, - Description: &description, - Schedule: &schedule, - StartOnCreation: &startOnCreation, - TriggerType: &triggerType, }, }, }, @@ -232,13 +325,10 @@ func TestIsUpToDate(t *testing.T) { Name: &triggerName, Actions: []*svcsdk.Action{ { - JobName: &actionsJobName, + JobName: &actionsJobName1, Timeout: &actionJobTimeout, }, }, - Description: &description, - Schedule: &schedule, - Type: &triggerType, }, }, }, @@ -247,7 +337,7 @@ func TestIsUpToDate(t *testing.T) { err: nil, }, }, - "ImmutableParamsChanged": { + "ActionRemoved": { args: args{ trigger: &svcapitypes.Trigger{ ObjectMeta: metav1.ObjectMeta{ @@ -258,17 +348,12 @@ func TestIsUpToDate(t *testing.T) { }, Spec: svcapitypes.TriggerSpec{ ForProvider: svcapitypes.TriggerParameters{ - Region: region, Actions: []*svcapitypes.Action{ { - JobName: &actionsJobName, - Timeout: &actionJobTimeout, + JobName: &actionsJobName2, + Timeout: &newActionJobTimeout, }, }, - Description: &description, - Schedule: &schedule, - StartOnCreation: &newStartOnCreation, - TriggerType: &newTriggerType, }, }, }, @@ -277,13 +362,330 @@ func TestIsUpToDate(t *testing.T) { Name: &triggerName, Actions: []*svcsdk.Action{ { - JobName: &actionsJobName, + JobName: &actionsJobName1, Timeout: &actionJobTimeout, }, + { + JobName: &actionsJobName2, + Timeout: &newActionJobTimeout, + }, }, - Description: &description, - Schedule: &schedule, - Type: &triggerType, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "EventBatchingConditionBatchSizeChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + EventBatchingCondition: &svcapitypes.EventBatchingCondition{ + BatchWindow: &eventBatchingConditionBatchWindow, + BatchSize: &newEventBatchingConditionBatchSize, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + EventBatchingCondition: &svcsdk.EventBatchingCondition{ + BatchWindow: &eventBatchingConditionBatchWindow, + BatchSize: &eventBatchingConditionBatchSize, + }, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "EventBatchingConditionBatchWindowChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + EventBatchingCondition: &svcapitypes.EventBatchingCondition{ + BatchWindow: &newEventBatchingConditionBatchWindow, + BatchSize: &eventBatchingConditionBatchSize, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + EventBatchingCondition: &svcsdk.EventBatchingCondition{ + BatchWindow: &eventBatchingConditionBatchWindow, + BatchSize: &eventBatchingConditionBatchSize, + }, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "PredicateConditionCrawlerStateChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + Predicate: &svcapitypes.Predicate{ + Conditions: []*svcapitypes.Condition{ + {CrawlState: &predicateConditionCrawlerStateRunning}, + }, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Predicate: &svcsdk.Predicate{ + Conditions: []*svcsdk.Condition{ + {CrawlState: &predicateConditionCrawlerStateReady}, + }, + }, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "PredicateConditionJobNameChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + Predicate: &svcapitypes.Predicate{ + Conditions: []*svcapitypes.Condition{ + {JobName: &newPredicateConditionJobName}, + }, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Predicate: &svcsdk.Predicate{ + Conditions: []*svcsdk.Condition{ + {JobName: &predicateConditionJobName}, + }, + }, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "PredicateConditionCrawlerNameChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + Predicate: &svcapitypes.Predicate{ + Conditions: []*svcapitypes.Condition{ + {CrawlerName: &newPredicateConditionCrawlerName}, + }, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Predicate: &svcsdk.Predicate{ + Conditions: []*svcsdk.Condition{ + {CrawlerName: &predicateConditionCrawlerName}, + }, + }, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "PredicateConditionLogicalOperatorAdded": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + Predicate: &svcapitypes.Predicate{ + Conditions: []*svcapitypes.Condition{ + {LogicalOperator: &predicateConditionLogicalOperator}, + }, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Predicate: &svcsdk.Predicate{ + Conditions: []*svcsdk.Condition{}, + }, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "PredicateConditionStateChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + Predicate: &svcapitypes.Predicate{ + Conditions: []*svcapitypes.Condition{ + {State: &predicateConditionStateSucceeded}, + }, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Predicate: &svcsdk.Predicate{ + Conditions: []*svcsdk.Condition{ + {State: &predicateConditionStateStopped}, + }, + }, + }, + }, + }, + }, + "PredicateLogicalChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + Predicate: &svcapitypes.Predicate{ + Logical: &newPredicateLogical, + }, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Predicate: &svcsdk.Predicate{ + Logical: &predicateLogical, + }, + }, + }, + }, + want: want{ + result: false, + err: nil, + }, + }, + "WorkflowNameChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + WorkflowName: &newWorkflowName, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + WorkflowName: &workflowName, + }, + }, + }, + }, + "ImmutableParamsChanged": { + args: args{ + trigger: &svcapitypes.Trigger{ + ObjectMeta: metav1.ObjectMeta{ + Name: triggerName, + Annotations: map[string]string{ + meta.AnnotationKeyExternalName: triggerName, + }, + }, + Spec: svcapitypes.TriggerSpec{ + ForProvider: svcapitypes.TriggerParameters{ + StartOnCreation: &newStartOnCreation, + TriggerType: &newTriggerType, + }, + }, + }, + getTriggerOutput: &svcsdk.GetTriggerOutput{ + Trigger: &svcsdk.Trigger{ + Name: &triggerName, + Type: &triggerType, }, }, },