Skip to content

Commit

Permalink
Merge pull request #2129 from crossplane-contrib/backport-2126-to-rel…
Browse files Browse the repository at this point in the history
…ease-0.50
  • Loading branch information
MisterMX authored Nov 27, 2024
2 parents e6c8c11 + 67c1792 commit 55eeb2a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
8 changes: 8 additions & 0 deletions apis/ecs/generator-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ ignore:
resource_names:
- CapacityProvider
- TaskSet
resources:
Service:
fields:
TaskArns:
is_read_only: true
from:
operation: ListTasks
path: TaskArns
operations:
DeregisterTaskDefinition:
operation_type:
Expand Down
11 changes: 11 additions & 0 deletions apis/ecs/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apis/ecs/v1alpha1/zz_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package/crds/ecs.aws.crossplane.io_services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,11 @@ spec:
description: The status of the service. The valid values are ACTIVE,
DRAINING, or INACTIVE.
type: string
taskARNs:
description: The list of task ARN entries for the ListTasks request.
items:
type: string
type: array
taskDefinition:
description: |-
The task definition to use for tasks in the service. This value is specified
Expand Down
22 changes: 20 additions & 2 deletions pkg/controller/ecs/service/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
svcsdk "github.com/aws/aws-sdk-go/service/ecs"
svcsdkapi "github.com/aws/aws-sdk-go/service/ecs/ecsiface"
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
"github.com/crossplane/crossplane-runtime/pkg/connection"
"github.com/crossplane/crossplane-runtime/pkg/controller"
Expand All @@ -14,22 +15,30 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pkg/errors"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

svcapitypes "github.com/crossplane-contrib/provider-aws/apis/ecs/v1alpha1"
"github.com/crossplane-contrib/provider-aws/apis/v1alpha1"
"github.com/crossplane-contrib/provider-aws/pkg/features"
custommanaged "github.com/crossplane-contrib/provider-aws/pkg/utils/reconciler/managed"
)

type custom struct {
kube client.Client
client svcsdkapi.ECSAPI
}

// SetupService adds a controller that reconciles Service.
func SetupService(mgr ctrl.Manager, o controller.Options) error {
name := managed.ControllerName(svcapitypes.ServiceGroupKind)
opts := []option{
func(e *external) {
c := &custom{client: e.client, kube: e.kube}
e.preObserve = preObserve
e.postObserve = postObserve
e.postObserve = c.postObserve
e.preCreate = preCreate
e.preUpdate = preUpdate
e.preDelete = preDelete
Expand Down Expand Up @@ -170,7 +179,7 @@ func preObserve(_ context.Context, cr *svcapitypes.Service, obj *svcsdk.Describe
return nil
}

func postObserve(_ context.Context, cr *svcapitypes.Service, resp *svcsdk.DescribeServicesOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) {
func (e *custom) postObserve(_ context.Context, cr *svcapitypes.Service, resp *svcsdk.DescribeServicesOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) {
if err != nil {
return obs, err
}
Expand All @@ -179,6 +188,15 @@ func postObserve(_ context.Context, cr *svcapitypes.Service, resp *svcsdk.Descri
return obs, err
}

listTasksOutput, err := e.client.ListTasks(&svcsdk.ListTasksInput{
Cluster: cr.Spec.ForProvider.Cluster,
ServiceName: aws.String(meta.GetExternalName(cr)),
})
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "ListTasks failed")
}
cr.Status.AtProvider.TaskARNs = listTasksOutput.TaskArns

switch aws.StringValue(resp.Services[0].Status) {
case "ACTIVE":
if resp.Services[0].DesiredCount == nil || resp.Services[0].RunningCount == nil || *resp.Services[0].DesiredCount != *resp.Services[0].RunningCount {
Expand Down

0 comments on commit 55eeb2a

Please sign in to comment.