Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revendor mcm v0.39.0 #17

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ module github.com/gardener/machine-controller-manager-provider-gcp
go 1.15

require (
github.com/gardener/machine-controller-manager v0.37.0
github.com/golang/protobuf v1.3.2 // indirect
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/gardener/machine-controller-manager v0.39.0
github.com/onsi/ginkgo v1.15.2
github.com/onsi/gomega v1.11.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.5.1 // indirect
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
google.golang.org/api v0.4.0
k8s.io/api v0.16.8
Expand Down
86 changes: 60 additions & 26 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions kubernetes/machine-class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: MachineClass
metadata:
name: test-mc
namespace: default # Namespace where the controller would watch
provider: GCP
providerSpec:
canIpForward: true # Allows this instance to send and receive packets with non-matching destination or source IPs
deletionProtection: false # DeletionProtection: Whether the resource should be protected against deletion
Expand Down
24 changes: 24 additions & 0 deletions pkg/gcp/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func (ms *MachinePlugin) CreateMachine(ctx context.Context, req *driver.CreateMa
// Log messages to track start of request
klog.V(2).Infof("Create machine request has been received for %q", req.Machine.Name)

// Check if the MachineClass is for the supported cloud provider
if req.MachineClass.Provider != ProviderGCP {
err := fmt.Errorf("Requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderGCP)
return nil, status.Error(codes.InvalidArgument, err.Error())
}

providerSpec, err := decodeProviderSpecAndSecret(req.MachineClass, req.Secret)
if err != nil {
return nil, prepareErrorf(err, "Create machine %q failed on decodeProviderSpecAndSecret", req.Machine.Name)
Expand Down Expand Up @@ -101,6 +107,12 @@ func (ms *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMa
// Log messages to track delete request
klog.V(2).Infof("Machine deletion request has been received for %q", req.Machine.Name)

// Check if the MachineClass is for the supported cloud provider
if req.MachineClass.Provider != ProviderGCP {
err := fmt.Errorf("Requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderGCP)
return nil, status.Error(codes.InvalidArgument, err.Error())
}

providerSpec, err := decodeProviderSpecAndSecret(req.MachineClass, req.Secret)
if err != nil {
return nil, prepareErrorf(err, "Delete machine %q failed on decodeProviderSpecAndSecret", req.Machine.Name)
Expand Down Expand Up @@ -136,6 +148,12 @@ func (ms *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMa
// Log messages to track start of request
klog.V(2).Infof("Machine status request has been received for %q", req.Machine.Name)

// Check if the MachineClass is for the supported cloud provider
if req.MachineClass.Provider != ProviderGCP {
err := fmt.Errorf("Requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderGCP)
return nil, status.Error(codes.InvalidArgument, err.Error())
}

providerSpec, err := decodeProviderSpecAndSecret(req.MachineClass, req.Secret)
if err != nil {
return nil, prepareErrorf(err, "Machine status %q failed on decodeProviderSpecAndSecret", req.Machine.Name)
Expand Down Expand Up @@ -173,6 +191,12 @@ func (ms *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachi
// Log messages to track start of request
klog.V(2).Infof("List machines request has been received")

// Check if the MachineClass is for the supported cloud provider
if req.MachineClass.Provider != ProviderGCP {
err := fmt.Errorf("Requested for Provider '%s', we only support '%s'", req.MachineClass.Provider, ProviderGCP)
return nil, status.Error(codes.InvalidArgument, err.Error())
}

providerSpec, err := decodeProviderSpecAndSecret(req.MachineClass, req.Secret)
if err != nil {
return nil, prepareErrorf(err, "List machines failed on decodeProviderSpecAndSecret")
Expand Down
90 changes: 69 additions & 21 deletions pkg/gcp/machine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const (
FailAtSpecValidation string = "machine codes error: code = [Internal] message = [Create machine \"dummy-machine\" failed on decodeProviderSpecAndSecret: machine codes error: code = [Internal] message = [Error while validating ProviderSpec [spec.zone: Required value: zone is required]]]"
// FailAtNonExistingMachine because existing machine is not found
FailAtNonExistingMachine string = "rpc error: code = NotFound desc = Machine with the name \"non-existent-dummy-machine\" not found"

UnsupportedProviderError string = "machine codes error: code = [InvalidArgument] message = [Requested for Provider 'aws', we only support 'GCP']"
)

var _ = Describe("#MachineController", func() {
Expand Down Expand Up @@ -180,7 +182,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -192,11 +194,24 @@ var _ = Describe("#MachineController", func() {
errToHaveOccurred: false,
},
}),
Entry("Creata a simple machine with unsupported provider in MachineClass", &data{
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec, "aws"),
Secret: newSecret(gcpProviderSecret),
},
},
expect: expect{
errToHaveOccurred: true,
errMessage: UnsupportedProviderError,
},
}),
Entry("With zone missing", &data{
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpecValidationErr),
MachineClass: newGCPMachineClass(gcpProviderSpecValidationErr, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -209,7 +224,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass([]byte("")),
MachineClass: newGCPMachineClass([]byte(""), ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -223,7 +238,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(make(map[string][]byte)),
},
},
Expand All @@ -236,7 +251,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(gcpProviderSecretWithMisssingUserData),
},
},
Expand All @@ -249,7 +264,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(gcpProviderSecretWithoutProjectID),
},
},
Expand All @@ -262,7 +277,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidPostZone),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidPostZone, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -275,7 +290,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand Down Expand Up @@ -319,7 +334,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.DeleteMachineRequest{
Machine: newMachine("non-existent-dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -330,11 +345,25 @@ var _ = Describe("#MachineController", func() {
},
}),

Entry("Delete machine request with unsupported provider in the MachineClass", &data{
action: action{
machineRequest: &driver.DeleteMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec, "aws"),
Secret: newSecret(gcpProviderSecret),
},
},
expect: expect{
errToHaveOccurred: true,
errMessage: UnsupportedProviderError,
},
}),

Entry("With no provider spec", &data{
action: action{
machineRequest: &driver.DeleteMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass([]byte("")),
MachineClass: newGCPMachineClass([]byte(""), ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -348,7 +377,7 @@ var _ = Describe("#MachineController", func() {
action: action{
machineRequest: &driver.DeleteMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand Down Expand Up @@ -419,12 +448,12 @@ var _ = Describe("#MachineController", func() {
action: action{
createRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(gcpProviderSecret),
},
createMachine: true,
listRequest: &driver.ListMachinesRequest{
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -441,7 +470,7 @@ var _ = Describe("#MachineController", func() {
action: action{
createMachine: false,
listRequest: &driver.ListMachinesRequest{
MachineClass: newGCPMachineClass([]byte("")),
MachineClass: newGCPMachineClass([]byte(""), ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -455,7 +484,7 @@ var _ = Describe("#MachineController", func() {
action: action{
createMachine: false,
listRequest: &driver.ListMachinesRequest{
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -465,6 +494,20 @@ var _ = Describe("#MachineController", func() {
errMessage: ListFailAtInvalidZoneListCall,
},
}),
Entry("List with Get call with unsupported provider in MachineClass", &data{
action: action{
createMachine: false,
listRequest: &driver.ListMachinesRequest{
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone, "aws"),
Secret: newSecret(gcpProviderSecret),
},
},
expect: expect{
errToHaveOccurred: true,
listErrToHaveOccurred: true,
errMessage: UnsupportedProviderError,
},
}),
)

})
Expand Down Expand Up @@ -532,7 +575,7 @@ var _ = Describe("#MachineController", func() {

getStatusRequest: &driver.GetMachineStatusRequest{
Machine: newMachine("non-existent-dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpecNoTagsToSearch),
MachineClass: newGCPMachineClass(gcpProviderSpecNoTagsToSearch, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -546,13 +589,13 @@ var _ = Describe("#MachineController", func() {
action: action{
createRequest: &driver.CreateMachineRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(gcpProviderSecret),
},
createMachine: true,
getStatusRequest: &driver.GetMachineStatusRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpec),
MachineClass: newGCPMachineClass(gcpProviderSpec, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -574,7 +617,7 @@ var _ = Describe("#MachineController", func() {
createMachine: false,
getStatusRequest: &driver.GetMachineStatusRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass([]byte("")),
MachineClass: newGCPMachineClass([]byte(""), ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand All @@ -589,7 +632,7 @@ var _ = Describe("#MachineController", func() {
createMachine: false,
getStatusRequest: &driver.GetMachineStatusRequest{
Machine: newMachine("dummy-machine"),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone),
MachineClass: newGCPMachineClass(gcpProviderSpecInvalidListZone, ""),
Secret: newSecret(gcpProviderSecret),
},
},
Expand Down Expand Up @@ -812,6 +855,7 @@ var _ = Describe("#MachineController", func() {
Name: TestMachineClassName,
Namespace: TestNamaspace,
},
Provider: ProviderGCP,
},
ClassSpec: &v1alpha1.ClassSpec{
Kind: GCPMachineClassKind,
Expand Down Expand Up @@ -862,11 +906,15 @@ func newMachine(name string) *v1alpha1.Machine {
}
}

func newGCPMachineClass(gcpProviderSpec []byte) *v1alpha1.MachineClass {
func newGCPMachineClass(gcpProviderSpec []byte, provider string) *v1alpha1.MachineClass {
if provider == "" {
provider = ProviderGCP
}
return &v1alpha1.MachineClass{
ProviderSpec: runtime.RawExtension{
Raw: gcpProviderSpec,
},
Provider: provider,
}
}

Expand Down
12 changes: 12 additions & 0 deletions vendor/github.com/fsnotify/fsnotify/.editorconfig

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

1 change: 1 addition & 0 deletions vendor/github.com/fsnotify/fsnotify/.gitattributes

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

36 changes: 36 additions & 0 deletions vendor/github.com/fsnotify/fsnotify/.travis.yml

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

Loading