forked from kubernetes-sigs/cluster-api-provider-gcp
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
processor map values need - to prevent mapping to wrong processor
- Loading branch information
Showing
2 changed files
with
86 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package scope_test | ||
|
||
import ( | ||
"testing" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1" | ||
"sigs.k8s.io/cluster-api-provider-gcp/cloud" | ||
"sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1" | ||
clusterv1exp "sigs.k8s.io/cluster-api/exp/api/v1beta1" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
"sigs.k8s.io/cluster-api-provider-gcp/cloud/scope" | ||
) | ||
|
||
|
||
var _ = Describe("GCPManagedMachinePool Scope", func() { | ||
var TestMachinePoolScope *scope.MachinePoolScope | ||
var getter cloud.ClusterGetter | ||
var t *testing.T | ||
|
||
BeforeEach(func() { | ||
// Register the MachinePool, GCPMachinePool and GCPMachinePoolList in a schema. | ||
schema, err := infrav1.SchemeBuilder.Register(&clusterv1exp.MachinePool{},&v1beta1.GCPMachinePool{}, &v1beta1.GCPMachinePoolList{}).Build() | ||
// Make sure no errors were triggered. | ||
assert.Nil(t, err) | ||
|
||
// Create a controller fake client. | ||
// It's best to use envtest but in this case we are not really using the client | ||
// just passing it as parameter to the NewMachinePoolScope to test the mincpu. | ||
testClient := fake.NewClientBuilder().WithScheme(schema).Build() | ||
|
||
// Create the machinepool scope | ||
params := scope.MachinePoolScopeParams{ | ||
Client: testClient, | ||
ClusterGetter: getter, | ||
MachinePool: &clusterv1exp.MachinePool{ | ||
ObjectMeta: metav1.ObjectMeta{}, | ||
Spec: clusterv1exp.MachinePoolSpec{}, | ||
}, | ||
GCPMachinePool: &v1beta1.GCPMachinePool{ | ||
ObjectMeta: metav1.ObjectMeta{}, | ||
Spec: v1beta1.GCPMachinePoolSpec{}, | ||
}, | ||
} | ||
TestMachinePoolScope, _ = scope.NewMachinePoolScope(params) | ||
|
||
// Make sure the machinepool scope is created correctly. | ||
assert.Nil(t, err) | ||
assert.NotNil(t, TestMachinePoolScope) | ||
|
||
}) | ||
|
||
Describe("Min CPU Mappings", func() { | ||
Context("instance types", func() { | ||
It("should match all", func() { | ||
for k := range(scope.Processors) { | ||
TestMachinePoolScope.GCPMachinePool.Spec.InstanceType = fmt.Sprintf("%sstandard-8", k) | ||
cpu := TestMachinePoolScope.MinCPUPlatform() | ||
Expect(cpu).To(Equal(scope.Processors[k])) | ||
} | ||
}) | ||
It("should not match n2", func() { | ||
TestMachinePoolScope.GCPMachinePool.Spec.InstanceType = "n2d-standard-8" | ||
cpu := TestMachinePoolScope.MinCPUPlatform() | ||
Expect(cpu).NotTo(Equal(scope.Processors["n2"])) | ||
}) | ||
}) | ||
}) | ||
}) |