Skip to content

Commit

Permalink
GZIP user-data (#710)
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <[email protected]>
  • Loading branch information
vincepri authored and k8s-ci-robot committed Apr 10, 2019
1 parent 4898eda commit a1943c6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/cloud/aws/services/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package ec2

import (
"bytes"
"compress/gzip"
"encoding/base64"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a1943c6

Please sign in to comment.