carlos / platform Public

grouprollaws: hold SDK operations as method values, not clients

The Adapter is converted to interfaces, so the linker kept every exported
method of the Auto Scaling, ELB, EC2 and SSM clients it held (the program
reflects on methods elsewhere). The linux/amd64 release binary grew from
70 MB to 108 MB, past execsandbox.BinaryLimit (96 MiB), and
TestExecSandboxProtocolReleaseBuild/amd64 failed. The adapter now holds
only the operations it calls; a test guards the field types.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5aa2e164902badb77d35ca17191f1c71acf540ab parent 8b1d94a
2 files changed, +115 −8
  • internal/grouprollaws/config_test.go +37 −0
  • internal/grouprollaws/group.go +78 −8
diff --git a/internal/grouprollaws/config_test.go b/internal/grouprollaws/config_test.go
index 7f805c706..038545590 100644
--- a/internal/grouprollaws/config_test.go
+++ b/internal/grouprollaws/config_test.go
@@ -510,3 +510,40 @@ source_profile = base
}
}
}
+
+// The Adapter holds no Auto Scaling, ELB, EC2 or SSM client, at any depth
+// of its fields: a client reachable from it keeps every operation of that
+// service in the release binary (see Adapter), which took it past
+// execsandbox.BinaryLimit.
+func TestAdapterHoldsNoLargeClient(t *testing.T) {
+ banned := map[string]bool{
+ "github.com/aws/aws-sdk-go-v2/service/autoscaling": true,
+ "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2": true,
+ "github.com/aws/aws-sdk-go-v2/service/ec2": true,
+ "github.com/aws/aws-sdk-go-v2/service/ssm": true,
+ }
+ seen := map[reflect.Type]bool{}
+ var walk func(ty reflect.Type, path string)
+ walk = func(ty reflect.Type, path string) {
+ if seen[ty] {
+ return
+ }
+ seen[ty] = true
+ if ty.Name() == "Client" && banned[ty.PkgPath()] {
+ t.Errorf("Adapter%s holds %s.Client", path, ty.PkgPath())
+ }
+ switch ty.Kind() {
+ case reflect.Pointer, reflect.Slice, reflect.Array, reflect.Map:
+ walk(ty.Elem(), path)
+ case reflect.Struct:
+ if ty.PkgPath() != "github.com/carlosframework/platform/internal/grouprollaws" {
+ return
+ }
+ for i := 0; i < ty.NumField(); i++ {
+ f := ty.Field(i)
+ walk(f.Type, path+"."+f.Name)
+ }
+ }
+ }
+ walk(reflect.TypeOf(Adapter{}), "")
+}
diff --git a/internal/grouprollaws/group.go b/internal/grouprollaws/group.go
index 275cf7436..bff9a5e13 100644
--- a/internal/grouprollaws/group.go
+++ b/internal/grouprollaws/group.go
@@ -36,13 +36,22 @@ var _ grouproll.Caller = (*Adapter)(nil)
// Adapter is the AWS side of grouproll.Group: the script's AWS.request for
// the group, target, hook, session-online, activity, membership, instance,
// template and write operations.
+//
+// The Auto Scaling, ELB, EC2 and SSM operations are held as method values
+// (the *Ops structs below), never as the SDK clients. The Adapter is
+// converted to interfaces, so every type reachable from its fields counts
+// as used in an interface, and the program reflects on methods elsewhere:
+// the linker then keeps every exported method of such a type. Holding the
+// four clients kept every one of their operations (EC2 alone has about
+// 800) and took the linux/amd64 release binary from 70 MB to 108 MB, past
+// execsandbox.BinaryLimit (96 MiB).
type Adapter struct {
c grouproll.Config
cfg aws.Config
- autoscaling *autoscaling.Client
- elb *elbv2.Client
- ec2 *ec2.Client
- ssm *ssm.Client
+ autoscaling autoscalingOps
+ elb elbOps
+ ec2 ec2Ops
+ ssm ssmOps
sts *sts.Client
s3 *s3.Client // objects.go: edges files, locks, release pointers
plugin pluginCheck // session.go: the plugin's path and version, once
@@ -59,15 +68,76 @@ func newAdapter(cfg aws.Config, c grouproll.Config) *Adapter {
return &Adapter{
c: c,
cfg: cfg,
- autoscaling: autoscaling.NewFromConfig(cfg, func(o *autoscaling.Options) { o.BaseEndpoint = nil }),
- elb: elbv2.NewFromConfig(cfg, func(o *elbv2.Options) { o.BaseEndpoint = nil }),
- ec2: ec2.NewFromConfig(cfg, func(o *ec2.Options) { o.BaseEndpoint = nil }),
- ssm: ssm.NewFromConfig(cfg, func(o *ssm.Options) { o.BaseEndpoint = nil }),
+ autoscaling: newAutoscalingOps(autoscaling.NewFromConfig(cfg, func(o *autoscaling.Options) { o.BaseEndpoint = nil })),
+ elb: newELBOps(elbv2.NewFromConfig(cfg, func(o *elbv2.Options) { o.BaseEndpoint = nil })),
+ ec2: newEC2Ops(ec2.NewFromConfig(cfg, func(o *ec2.Options) { o.BaseEndpoint = nil })),
+ ssm: newSSMOps(ssm.NewFromConfig(cfg, func(o *ssm.Options) { o.BaseEndpoint = nil })),
sts: sts.NewFromConfig(cfg, func(o *sts.Options) { o.BaseEndpoint = nil }),
s3: newS3(cfg),
}
}
+// The operations the adapter calls, one method value each (see Adapter).
+// Options is the client's configuration, for the plugin's endpoint and the
+// transport tests.
+type autoscalingOps struct {
+ DescribeAutoScalingGroups func(context.Context, *autoscaling.DescribeAutoScalingGroupsInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeAutoScalingGroupsOutput, error)
+ DescribeLifecycleHooks func(context.Context, *autoscaling.DescribeLifecycleHooksInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeLifecycleHooksOutput, error)
+ DescribeScalingActivities func(context.Context, *autoscaling.DescribeScalingActivitiesInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeScalingActivitiesOutput, error)
+ DescribeAutoScalingInstances func(context.Context, *autoscaling.DescribeAutoScalingInstancesInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeAutoScalingInstancesOutput, error)
+ UpdateAutoScalingGroup func(context.Context, *autoscaling.UpdateAutoScalingGroupInput, ...func(*autoscaling.Options)) (*autoscaling.UpdateAutoScalingGroupOutput, error)
+ EnterStandby func(context.Context, *autoscaling.EnterStandbyInput, ...func(*autoscaling.Options)) (*autoscaling.EnterStandbyOutput, error)
+ ExitStandby func(context.Context, *autoscaling.ExitStandbyInput, ...func(*autoscaling.Options)) (*autoscaling.ExitStandbyOutput, error)
+ TerminateInstanceInAutoScalingGroup func(context.Context, *autoscaling.TerminateInstanceInAutoScalingGroupInput, ...func(*autoscaling.Options)) (*autoscaling.TerminateInstanceInAutoScalingGroupOutput, error)
+ Options func() autoscaling.Options
+}
+
+func newAutoscalingOps(c *autoscaling.Client) autoscalingOps {
+ return autoscalingOps{
+ DescribeAutoScalingGroups: c.DescribeAutoScalingGroups,
+ DescribeLifecycleHooks: c.DescribeLifecycleHooks,
+ DescribeScalingActivities: c.DescribeScalingActivities,
+ DescribeAutoScalingInstances: c.DescribeAutoScalingInstances,
+ UpdateAutoScalingGroup: c.UpdateAutoScalingGroup,
+ EnterStandby: c.EnterStandby,
+ ExitStandby: c.ExitStandby,
+ TerminateInstanceInAutoScalingGroup: c.TerminateInstanceInAutoScalingGroup,
+ Options: c.Options,
+ }
+}
+
+type elbOps struct {
+ DescribeTargetHealth func(context.Context, *elbv2.DescribeTargetHealthInput, ...func(*elbv2.Options)) (*elbv2.DescribeTargetHealthOutput, error)
+ Options func() elbv2.Options
+}
+
+func newELBOps(c *elbv2.Client) elbOps {
+ return elbOps{DescribeTargetHealth: c.DescribeTargetHealth, Options: c.Options}
+}
+
+type ec2Ops struct {
+ DescribeInstances func(context.Context, *ec2.DescribeInstancesInput, ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error)
+ DescribeLaunchTemplateVersions func(context.Context, *ec2.DescribeLaunchTemplateVersionsInput, ...func(*ec2.Options)) (*ec2.DescribeLaunchTemplateVersionsOutput, error)
+ Options func() ec2.Options
+}
+
+func newEC2Ops(c *ec2.Client) ec2Ops {
+ return ec2Ops{DescribeInstances: c.DescribeInstances,
+ DescribeLaunchTemplateVersions: c.DescribeLaunchTemplateVersions, Options: c.Options}
+}
+
+type ssmOps struct {
+ DescribeInstanceInformation func(context.Context, *ssm.DescribeInstanceInformationInput, ...func(*ssm.Options)) (*ssm.DescribeInstanceInformationOutput, error)
+ StartSession func(context.Context, *ssm.StartSessionInput, ...func(*ssm.Options)) (*ssm.StartSessionOutput, error)
+ TerminateSession func(context.Context, *ssm.TerminateSessionInput, ...func(*ssm.Options)) (*ssm.TerminateSessionOutput, error)
+ Options func() ssm.Options
+}
+
+func newSSMOps(c *ssm.Client) ssmOps {
+ return ssmOps{DescribeInstanceInformation: c.DescribeInstanceInformation, StartSession: c.StartSession,
+ TerminateSession: c.TerminateSession, Options: c.Options}
+}
+
// call runs one provider call under the script's 15-second process bound
// and turns every failure into Uncertain(api), as the script's invoke does:
// a call past the bound or a stalled read is Uncertain{Timeout: true}, an