Skip to content

Commit

Permalink
chore: Update GetSupportedNodeClasses to return []status.Object
Browse files Browse the repository at this point in the history
  • Loading branch information
jigisha620 committed Jul 8, 2024
1 parent 8cdece6 commit 70fdfa4
Show file tree
Hide file tree
Showing 24 changed files with 198 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ func main() {
op.InstanceTypesProvider,
)...).
WithWebhooks(ctx, webhooks.NewWebhooks()...).
Start(ctx)
Start(ctx, cloudProvider)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
knative.dev/pkg v0.0.0-20231010144348-ca8c009405dd
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/karpenter v0.37.1-0.20240629051434-89a81c3ae853
sigs.k8s.io/karpenter v0.37.1-0.20240705194601-4a72da3afe8e
sigs.k8s.io/yaml v1.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,8 @@ sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHv
sigs.k8s.io/controller-runtime v0.18.4/go.mod h1:TVoGrfdpbA9VRFaRnKgk9P5/atA0pMwq+f+msb9M8Sg=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/karpenter v0.37.1-0.20240629051434-89a81c3ae853 h1:WAFMsZJpnScxrsXBsbou0hsZJOQRFS1RxRXb4Ee/cs4=
sigs.k8s.io/karpenter v0.37.1-0.20240629051434-89a81c3ae853/go.mod h1:jPA1J954ZvzJelythD9EtkrQXZLPUrZaMhQJ4MBRQ/Q=
sigs.k8s.io/karpenter v0.37.1-0.20240705194601-4a72da3afe8e h1:FriyVb7NI+MsIlHW93QgHDWfhVf8Gt0E2NNYy+WA3Jg=
sigs.k8s.io/karpenter v0.37.1-0.20240705194601-4a72da3afe8e/go.mod h1:Capmf9EwVSBoANOkP5qy4xHBaZ9/y0wUDyh4UzgRJlk=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
Expand Down
152 changes: 152 additions & 0 deletions pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,26 @@ spec:
- jsonPath: .spec.template.spec.nodeClassRef.name
name: NodeClass
type: string
- jsonPath: .status.resources.nodes
name: Nodes
type: string
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
- jsonPath: .spec.weight
name: Weight
priority: 1
type: integer
- jsonPath: .status.resources.cpu
name: CPU
priority: 1
type: string
- jsonPath: .status.resources.memory
name: Memory
priority: 1
type: string
name: v1
schema:
Expand Down Expand Up @@ -94,6 +111,19 @@ spec:
Ref: https://github.com/kubernetes-sigs/controller-tools/blob/55efe4be40394a288216dab63156b0a64fb82929/pkg/crd/markers/validation.go#L379-L388
pattern: ^((100|[0-9]{1,2})%|[0-9]+)$
type: string
reasons:
description: |-
Reasons is a list of disruption methods that this budget applies to. If Reasons is not set, this budget applies to all methods.
Otherwise, this will apply to each reason defined.
allowed reasons are underutilized, empty, and drifted.
items:
description: DisruptionReason defines valid reasons for disruption budgets.
enum:
- underutilized
- empty
- drifted
type: string
type: array
schedule:
description: |-
Schedule specifies when a budget begins being active, following
Expand Down Expand Up @@ -383,6 +413,67 @@ spec:
status:
description: NodePoolStatus defines the observed state of NodePool
properties:
conditions:
description: Conditions contains signals for health and readiness
items:
description: Condition aliases the upstream type and adds additional helper methods
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
resources:
additionalProperties:
anyOf:
Expand Down Expand Up @@ -902,6 +993,67 @@ spec:
status:
description: NodePoolStatus defines the observed state of NodePool
properties:
conditions:
description: Conditions contains signals for health and readiness
items:
description: Condition aliases the upstream type and adds additional helper methods
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
resources:
additionalProperties:
anyOf:
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/v1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package v1_test

import (
"context"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"testing"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -41,7 +42,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...))
awsEnv = test.NewEnvironment(ctx, env)
})

Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/v1beta1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package v1beta1_test

import (
"context"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"testing"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -41,7 +42,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...))
awsEnv = test.NewEnvironment(ctx, env)
})

Expand Down
5 changes: 2 additions & 3 deletions pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

"github.com/aws/aws-sdk-go/service/ec2"
"github.com/awslabs/operatorpkg/object"
"github.com/awslabs/operatorpkg/status"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -220,8 +219,8 @@ func (c *CloudProvider) Name() string {
return "aws"
}

func (c *CloudProvider) GetSupportedNodeClasses() []schema.GroupVersionKind {
return []schema.GroupVersionKind{object.GVK(&v1beta1.EC2NodeClass{})}
func (c *CloudProvider) GetSupportedNodeClasses() []status.Object {
return []status.Object{&v1beta1.EC2NodeClass{}}
}

func (c *CloudProvider) resolveNodeClassFromNodeClaim(ctx context.Context, nodeClaim *corev1beta1.NodeClaim) (*v1beta1.EC2NodeClass, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cloudprovider/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"net"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -77,7 +78,7 @@ func TestAWS(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...))
ctx = coreoptions.ToContext(ctx, coretest.Options())
ctx = options.ToContext(ctx, test.Options())
ctx, stop = context.WithCancel(ctx)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/interruption/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"testing"
"time"

Expand Down Expand Up @@ -75,7 +76,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...))
fakeClock = &clock.FakeClock{}
unavailableOfferingsCache = awscache.NewUnavailableOfferings()
sqsapi = &fake.SQSAPI{}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/nodeclaim/garbagecollection/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package garbagecollection_test
import (
"context"
"fmt"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -60,7 +61,7 @@ func TestAPIs(t *testing.T) {

var _ = BeforeSuite(func() {
ctx = options.ToContext(ctx, test.Options())
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...))
awsEnv = test.NewEnvironment(ctx, env)
cloudProvider = cloudprovider.New(awsEnv.InstanceTypesProvider, awsEnv.InstanceProvider, events.NewRecorder(&record.FakeRecorder{}),
env.Client, awsEnv.AMIProvider, awsEnv.SecurityGroupProvider)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/nodeclaim/tagging/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package tagging_test
import (
"context"
"fmt"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -54,7 +55,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...))
ctx = coreoptions.ToContext(ctx, coretest.Options())
ctx = options.ToContext(ctx, test.Options())
awsEnv = test.NewEnvironment(ctx, env)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/nodeclass/hash/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package hash_test

import (
"context"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -50,7 +51,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithFieldIndexers(test.EC2NodeClassFieldIndexer(ctx)))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...), coretest.WithFieldIndexers(test.EC2NodeClassFieldIndexer(ctx)))
ctx = coreoptions.ToContext(ctx, coretest.Options())
ctx = options.ToContext(ctx, test.Options())
awsEnv = test.NewEnvironment(ctx, env)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/nodeclass/status/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package status_test

import (
"context"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"testing"

coreoptions "sigs.k8s.io/karpenter/pkg/operator/options"
Expand Down Expand Up @@ -46,7 +47,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithFieldIndexers(test.EC2NodeClassFieldIndexer(ctx)))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...), coretest.WithFieldIndexers(test.EC2NodeClassFieldIndexer(ctx)))
ctx = coreoptions.ToContext(ctx, coretest.Options())
ctx = options.ToContext(ctx, test.Options())
awsEnv = test.NewEnvironment(ctx, env)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/nodeclass/termination/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package termination_test
import (
"context"
"fmt"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"testing"
"time"

Expand Down Expand Up @@ -57,7 +58,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithFieldIndexers(test.EC2NodeClassFieldIndexer(ctx)))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...), coretest.WithFieldIndexers(test.EC2NodeClassFieldIndexer(ctx)))
ctx = coreoptions.ToContext(ctx, coretest.Options())
ctx = options.ToContext(ctx, test.Options())
awsEnv = test.NewEnvironment(ctx, env)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/providers/instancetype/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package instancetype_test

import (
"context"
"sigs.k8s.io/karpenter/pkg/test/v1alpha1"
"testing"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -52,7 +53,7 @@ func TestAWS(t *testing.T) {
}

var _ = BeforeSuite(func() {
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...))
env = coretest.NewEnvironment(coretest.WithCRDs(apis.CRDs...), coretest.WithCRDs(v1alpha1.CRDs...))
ctx = coreoptions.ToContext(ctx, coretest.Options())
ctx = options.ToContext(ctx, test.Options())
ctx, stop = context.WithCancel(ctx)
Expand Down
Loading

0 comments on commit 70fdfa4

Please sign in to comment.