From a1943c6b1785f569f4e3a93a043a78aa81bbcab2 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Wed, 10 Apr 2019 09:36:17 -0700 Subject: [PATCH] GZIP user-data (#710) Signed-off-by: Vince Prignano --- pkg/cloud/aws/services/ec2/instances.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/cloud/aws/services/ec2/instances.go b/pkg/cloud/aws/services/ec2/instances.go index a900ccc1ed..c84f2964c3 100644 --- a/pkg/cloud/aws/services/ec2/instances.go +++ b/pkg/cloud/aws/services/ec2/instances.go @@ -17,6 +17,8 @@ limitations under the License. package ec2 import ( + "bytes" + "compress/gzip" "encoding/base64" "github.com/aws/aws-sdk-go/aws" @@ -364,11 +366,21 @@ func (s *Service) runInstance(role string, i *v1alpha1.Instance) (*v1alpha1.Inst EbsOptimized: i.EBSOptimized, MaxCount: aws.Int64(1), MinCount: aws.Int64(1), - UserData: i.UserData, } if i.UserData != nil { - input.UserData = aws.String(base64.StdEncoding.EncodeToString([]byte(*i.UserData))) + var buf bytes.Buffer + + gz := gzip.NewWriter(&buf) + if _, err := gz.Write([]byte(*i.UserData)); err != nil { + return nil, errors.Wrap(err, "failed to gzip userdata") + } + + if err := gz.Close(); err != nil { + return nil, errors.Wrap(err, "failed to gzip userdata") + } + + input.UserData = aws.String(base64.StdEncoding.EncodeToString(buf.Bytes())) } if len(i.SecurityGroupIDs) > 0 {