Skip to content

Commit

Permalink
Merge pull request #2913 from weaveworks/emr-support
Browse files Browse the repository at this point in the history
Support enabling access for EMR containers
  • Loading branch information
cPu1 authored Dec 9, 2020
2 parents 292bd86 + 805ffe3 commit 9731725
Show file tree
Hide file tree
Showing 10 changed files with 564 additions and 42 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ generate-always: pkg/addons/default/assets/aws-node.yaml ## Generate code (requi
go generate ./pkg/nodebootstrap
go generate ./pkg/addons/default/generate.go
go generate ./pkg/addons
go generate ./pkg/authconfigmap
# mocks
go generate ./pkg/eks
go generate ./pkg/drain
Expand Down
5 changes: 3 additions & 2 deletions pkg/addons/device_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/kris-nova/logger"
"github.com/pkg/errors"
"github.com/weaveworks/eksctl/pkg/assetutil"
"github.com/weaveworks/eksctl/pkg/kubernetes"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -126,7 +127,7 @@ func (n *NeuronDevicePlugin) PlanMode() bool {
}

func (n *NeuronDevicePlugin) Manifest() []byte {
return mustGenerateAsset(neuronDevicePluginYamlBytes)
return assetutil.MustLoad(neuronDevicePluginYamlBytes)
}

func (n *NeuronDevicePlugin) SetImage(t *v1.PodTemplateSpec) error {
Expand Down Expand Up @@ -167,7 +168,7 @@ func (n *NvidiaDevicePlugin) SetImage(t *v1.PodTemplateSpec) error {
}

func (n *NvidiaDevicePlugin) Manifest() []byte {
return mustGenerateAsset(nvidiaDevicePluginYamlBytes)
return assetutil.MustLoad(nvidiaDevicePluginYamlBytes)
}

// Deploy deploys the Nvidia device plugin to the specified cluster
Expand Down
33 changes: 8 additions & 25 deletions pkg/addons/vpc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/kris-nova/logger"
"github.com/pkg/errors"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/assetutil"
"github.com/weaveworks/eksctl/pkg/kubernetes"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes/typed/certificates/v1beta1"
Expand Down Expand Up @@ -50,7 +51,7 @@ type VPCController struct {
func (v *VPCController) Deploy() (err error) {
defer func() {
if r := recover(); r != nil {
if ae, ok := r.(*assetError); ok {
if ae, ok := r.(*assetutil.Error); ok {
err = ae
} else {
panic(r)
Expand Down Expand Up @@ -107,7 +108,7 @@ func (v *VPCController) generateCert() error {
return errors.Wrap(err, "generating CSR")
}

manifest := mustGenerateAsset(vpcAdmissionWebhookCsrYamlBytes)
manifest := assetutil.MustLoad(vpcAdmissionWebhookCsrYamlBytes)
rawExtension, err := kubernetes.NewRawExtension(manifest)
if err != nil {
return err
Expand Down Expand Up @@ -207,21 +208,21 @@ func (v *VPCController) createCertSecrets(key, cert []byte) error {
}

func (v *VPCController) deployVPCResourceController() error {
if err := v.applyResources(mustGenerateAsset(vpcResourceControllerYamlBytes)); err != nil {
if err := v.applyResources(assetutil.MustLoad(vpcResourceControllerYamlBytes)); err != nil {
return err
}
return v.applyDeployment(mustGenerateAsset(vpcResourceControllerDepYamlBytes))
return v.applyDeployment(assetutil.MustLoad(vpcResourceControllerDepYamlBytes))
}

func (v *VPCController) deployVPCWebhook() error {
if err := v.applyResources(mustGenerateAsset(vpcAdmissionWebhookYamlBytes)); err != nil {
if err := v.applyResources(assetutil.MustLoad(vpcAdmissionWebhookYamlBytes)); err != nil {
return err
}
if err := v.applyDeployment(mustGenerateAsset(vpcAdmissionWebhookDepYamlBytes)); err != nil {
if err := v.applyDeployment(assetutil.MustLoad(vpcAdmissionWebhookDepYamlBytes)); err != nil {
return err
}

manifest := mustGenerateAsset(vpcAdmissionWebhookConfigYamlBytes)
manifest := assetutil.MustLoad(vpcAdmissionWebhookConfigYamlBytes)
rawExtension, err := kubernetes.NewRawExtension(manifest)
if err != nil {
return err
Expand Down Expand Up @@ -333,24 +334,6 @@ func (v *VPCController) applyRawResource(object runtime.Object) error {
return nil
}

type assetError struct {
error
}

func (ae *assetError) Error() string {
return fmt.Sprintf("unexpected error generating assets: %v", ae.error.Error())
}

type assetFunc func() ([]byte, error)

func mustGenerateAsset(assetFunc assetFunc) []byte {
bytes, err := assetFunc()
if err != nil {
panic(&assetError{err})
}
return bytes
}

func generateCertReq(service, namespace string) ([]byte, []byte, error) {
generator := csr.Generator{
Validator: func(request *csr.CertificateRequest) error {
Expand Down
26 changes: 26 additions & 0 deletions pkg/assetutil/assetutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package assetutil

import (
"fmt"
)

// Error describes an asset error
type Error struct {
error
}

func (ae *Error) Error() string {
return fmt.Sprintf("unexpected error generating assets: %v", ae.error.Error())
}

// Func describes an asset loading function
type Func func() ([]byte, error)

// MustLoad loads an asset or panics if the asset couldn't be loaded
func MustLoad(assetFunc Func) []byte {
bytes, err := assetFunc()
if err != nil {
panic(&Error{err})
}
return bytes
}
Loading

0 comments on commit 9731725

Please sign in to comment.