Skip to content

Commit

Permalink
feat: Get the GVK of the supported NodeClasses as part of the CloudPr…
Browse files Browse the repository at this point in the history
…ovider interface (#1146)
  • Loading branch information
engedaam committed Mar 29, 2024
1 parent c8eda9b commit 3d51e28
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions kwok/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -118,6 +119,10 @@ func (c CloudProvider) Name() string {
return "kwok"
}

func (c CloudProvider) GetSupportedNodeClasses() []schema.GroupVersionKind {
return []schema.GroupVersionKind{}
}

func (c CloudProvider) getInstanceType(instanceTypeName string) (*cloudprovider.InstanceType, error) {
it, found := lo.Find(c.instanceTypes, func(it *cloudprovider.InstanceType) bool {
return it.Name == instanceTypeName
Expand Down
17 changes: 15 additions & 2 deletions pkg/cloudprovider/fake/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"

"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
Expand All @@ -51,8 +52,9 @@ type CloudProvider struct {
NextCreateErr error
DeleteCalls []*v1beta1.NodeClaim

CreatedNodeClaims map[string]*v1beta1.NodeClaim
Drifted cloudprovider.DriftReason
CreatedNodeClaims map[string]*v1beta1.NodeClaim
Drifted cloudprovider.DriftReason
NodeClassGroupVersionKind []schema.GroupVersionKind
}

func NewCloudProvider() *CloudProvider {
Expand All @@ -77,6 +79,13 @@ func (c *CloudProvider) Reset() {
c.NextCreateErr = nil
c.DeleteCalls = []*v1beta1.NodeClaim{}
c.Drifted = "drifted"
c.NodeClassGroupVersionKind = []schema.GroupVersionKind{
{
Group: "",
Version: "",
Kind: "",
},
}
}

func (c *CloudProvider) Create(ctx context.Context, nodeClaim *v1beta1.NodeClaim) (*v1beta1.NodeClaim, error) {
Expand Down Expand Up @@ -237,3 +246,7 @@ func (c *CloudProvider) IsDrifted(context.Context, *v1beta1.NodeClaim) (cloudpro
func (c *CloudProvider) Name() string {
return "fake"
}

func (c *CloudProvider) GetSupportedNodeClasses() []schema.GroupVersionKind {
return c.NodeClassGroupVersionKind
}
3 changes: 3 additions & 0 deletions pkg/cloudprovider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
"sigs.k8s.io/karpenter/pkg/scheduling"
Expand Down Expand Up @@ -55,6 +56,8 @@ type CloudProvider interface {
IsDrifted(context.Context, *v1beta1.NodeClaim) (DriftReason, error)
// Name returns the CloudProvider implementation name.
Name() string
// GetSupportedNodeClass returns the group, version, and kind of the CloudProvider NodeClass
GetSupportedNodeClasses() []schema.GroupVersionKind
}

// InstanceType describes the properties of a potential node (either concrete attributes of an instance of this type
Expand Down

0 comments on commit 3d51e28

Please sign in to comment.