Skip to content

Commit

Permalink
chore: Simplify scheme to use clientgoscheme (#6422)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn authored Jun 27, 2024
1 parent 7bc4aad commit d37e5a2
Show file tree
Hide file tree
Showing 43 changed files with 135 additions and 223 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ run: ## Run Karpenter controller binary against your local cluster
go run ./cmd/controller/main.go

test: ## Run tests
go test -v ./pkg/... \
go test ./pkg/... \
-cover -coverprofile=coverage.out -outputdir=. -coverpkg=./... \
--ginkgo.focus="${FOCUS}" \
--ginkgo.randomize-all \
Expand Down
2 changes: 0 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"sigs.k8s.io/karpenter/pkg/cloudprovider/metrics"
corecontrollers "sigs.k8s.io/karpenter/pkg/controllers"
"sigs.k8s.io/karpenter/pkg/controllers/state"
coreoperator "sigs.k8s.io/karpenter/pkg/operator"
corewebhooks "sigs.k8s.io/karpenter/pkg/webhooks"
)
Expand All @@ -47,7 +46,6 @@ func main() {
WithControllers(ctx, corecontrollers.NewControllers(
op.Clock,
op.GetClient(),
state.NewCluster(op.Clock, op.GetClient(), cloudProvider),
op.EventRecorder,
cloudProvider,
)...).
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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.20240626220530-d33d38727888
sigs.k8s.io/karpenter v0.37.1-0.20240627203024-f66fd07b6fbb
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 @@ -761,8 +761,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.20240626220530-d33d38727888 h1:M9v0CldRB/YW6S8dmV+qqN3FOnvbxrowAiJW/UK/W+s=
sigs.k8s.io/karpenter v0.37.1-0.20240626220530-d33d38727888/go.mod h1:b2WP5LvtWNjec0JaTuzoxYnp6XXoBG9Bed1VzQwlaSw=
sigs.k8s.io/karpenter v0.37.1-0.20240627203024-f66fd07b6fbb h1:FZWiUjcJ52G8qcSKg0VeYxWtRDMfLWCQQ31tCqgfEME=
sigs.k8s.io/karpenter v0.37.1-0.20240627203024-f66fd07b6fbb/go.mod h1:b2WP5LvtWNjec0JaTuzoxYnp6XXoBG9Bed1VzQwlaSw=
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
15 changes: 1 addition & 14 deletions pkg/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,16 @@ import (
_ "embed"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"

v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1"
"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"

"github.com/samber/lo"

"sigs.k8s.io/karpenter/pkg/apis"
"sigs.k8s.io/karpenter/pkg/utils/functional"
)

var (
// Builder includes all types within the apis package
Builder = runtime.NewSchemeBuilder(
v1beta1.SchemeBuilder.AddToScheme,
v1.SchemeBuilder.AddToScheme,
)
// AddToScheme may be used to add all resources defined in the project to a Scheme
AddToScheme = Builder.AddToScheme
)

//go:generate controller-gen crd object:headerFile="../../hack/boilerplate.go.txt" paths="./..." output:crd:artifacts:config=crds
var (
Group = "karpenter.k8s.aws"
//go:embed crds/karpenter.k8s.aws_ec2nodeclasses.yaml
EC2NodeClassCRD []byte
CRDs = append(apis.CRDs,
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ spec:
- spec
type: object
served: true
storage: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
Expand Down Expand Up @@ -896,6 +896,6 @@ spec:
- spec
type: object
served: true
storage: false
storage: true
subresources:
status: {}
4 changes: 2 additions & 2 deletions pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ spec:
- spec
type: object
served: true
storage: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
Expand Down Expand Up @@ -1043,6 +1043,6 @@ spec:
- spec
type: object
served: true
storage: false
storage: true
subresources:
status: {}
16 changes: 16 additions & 0 deletions pkg/apis/v1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ limitations under the License.
// +k8s:defaulter-gen=TypeMeta
// +groupName=karpenter.k8s.aws
package v1 // doc.go is discovered by codegen

import (
"github.com/aws/karpenter-provider-aws/pkg/apis"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
)

func init() {
gv := schema.GroupVersion{Group: apis.Group, Version: "v1"}
v1.AddToGroupVersion(scheme.Scheme, gv)
scheme.Scheme.AddKnownTypes(gv,
&EC2NodeClass{},
&EC2NodeClassList{},
)
}
57 changes: 29 additions & 28 deletions pkg/apis/v1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"fmt"
"regexp"

"github.com/aws/karpenter-provider-aws/pkg/apis"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"

coreapis "sigs.k8s.io/karpenter/pkg/apis"
"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
)

Expand Down Expand Up @@ -52,7 +53,7 @@ func init() {
}

var (
TerminationFinalizer = Group + "/termination"
TerminationFinalizer = apis.Group + "/termination"
AWSToKubeArchitectures = map[string]string{
"x86_64": v1beta1.ArchitectureAmd64,
v1beta1.ArchitectureArm64: v1beta1.ArchitectureArm64,
Expand All @@ -62,7 +63,7 @@ var (
v1beta1.ArchitectureArm64,
)
RestrictedLabelDomains = []string{
Group,
apis.Group,
}
RestrictedTagPatterns = []*regexp.Regexp{
// Adheres to cluster name pattern matching as specified in the API spec
Expand Down Expand Up @@ -93,34 +94,34 @@ var (
ResourcePrivateIPv4Address v1.ResourceName = "vpc.amazonaws.com/PrivateIPv4Address"
ResourceEFA v1.ResourceName = "vpc.amazonaws.com/efa"

LabelNodeClass = Group + "/ec2nodeclass"
LabelNodeClass = apis.Group + "/ec2nodeclass"

LabelTopologyZoneID = "topology.k8s.aws/zone-id"

LabelInstanceHypervisor = Group + "/instance-hypervisor"
LabelInstanceEncryptionInTransitSupported = Group + "/instance-encryption-in-transit-supported"
LabelInstanceCategory = Group + "/instance-category"
LabelInstanceFamily = Group + "/instance-family"
LabelInstanceGeneration = Group + "/instance-generation"
LabelInstanceLocalNVME = Group + "/instance-local-nvme"
LabelInstanceSize = Group + "/instance-size"
LabelInstanceCPU = Group + "/instance-cpu"
LabelInstanceCPUManufacturer = Group + "/instance-cpu-manufacturer"
LabelInstanceMemory = Group + "/instance-memory"
LabelInstanceEBSBandwidth = Group + "/instance-ebs-bandwidth"
LabelInstanceNetworkBandwidth = Group + "/instance-network-bandwidth"
LabelInstanceGPUName = Group + "/instance-gpu-name"
LabelInstanceGPUManufacturer = Group + "/instance-gpu-manufacturer"
LabelInstanceGPUCount = Group + "/instance-gpu-count"
LabelInstanceGPUMemory = Group + "/instance-gpu-memory"
LabelInstanceAcceleratorName = Group + "/instance-accelerator-name"
LabelInstanceAcceleratorManufacturer = Group + "/instance-accelerator-manufacturer"
LabelInstanceAcceleratorCount = Group + "/instance-accelerator-count"
AnnotationEC2NodeClassHash = Group + "/ec2nodeclass-hash"
AnnotationEC2NodeClassHashVersion = Group + "/ec2nodeclass-hash-version"
AnnotationInstanceTagged = Group + "/tagged"
LabelInstanceHypervisor = apis.Group + "/instance-hypervisor"
LabelInstanceEncryptionInTransitSupported = apis.Group + "/instance-encryption-in-transit-supported"
LabelInstanceCategory = apis.Group + "/instance-category"
LabelInstanceFamily = apis.Group + "/instance-family"
LabelInstanceGeneration = apis.Group + "/instance-generation"
LabelInstanceLocalNVME = apis.Group + "/instance-local-nvme"
LabelInstanceSize = apis.Group + "/instance-size"
LabelInstanceCPU = apis.Group + "/instance-cpu"
LabelInstanceCPUManufacturer = apis.Group + "/instance-cpu-manufacturer"
LabelInstanceMemory = apis.Group + "/instance-memory"
LabelInstanceEBSBandwidth = apis.Group + "/instance-ebs-bandwidth"
LabelInstanceNetworkBandwidth = apis.Group + "/instance-network-bandwidth"
LabelInstanceGPUName = apis.Group + "/instance-gpu-name"
LabelInstanceGPUManufacturer = apis.Group + "/instance-gpu-manufacturer"
LabelInstanceGPUCount = apis.Group + "/instance-gpu-count"
LabelInstanceGPUMemory = apis.Group + "/instance-gpu-memory"
LabelInstanceAcceleratorName = apis.Group + "/instance-accelerator-name"
LabelInstanceAcceleratorManufacturer = apis.Group + "/instance-accelerator-manufacturer"
LabelInstanceAcceleratorCount = apis.Group + "/instance-accelerator-count"
AnnotationEC2NodeClassHash = apis.Group + "/ec2nodeclass-hash"
AnnotationEC2NodeClassHashVersion = apis.Group + "/ec2nodeclass-hash-version"
AnnotationInstanceTagged = apis.Group + "/tagged"

TagNodeClaim = v1beta1.Group + "/nodeclaim"
TagManagedLaunchTemplate = Group + "/cluster"
TagNodeClaim = coreapis.Group + "/nodeclaim"
TagManagedLaunchTemplate = apis.Group + "/cluster"
TagName = "Name"
)
34 changes: 0 additions & 34 deletions pkg/apis/v1/register.go

This file was deleted.

3 changes: 1 addition & 2 deletions pkg/apis/v1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

. "sigs.k8s.io/karpenter/pkg/test/expectations"

"sigs.k8s.io/karpenter/pkg/operator/scheme"
coretest "sigs.k8s.io/karpenter/pkg/test"

"github.com/aws/karpenter-provider-aws/pkg/apis"
Expand All @@ -42,7 +41,7 @@ func TestAPIs(t *testing.T) {
}

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/v1/zz_generated.deepcopy.go

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

16 changes: 16 additions & 0 deletions pkg/apis/v1beta1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ limitations under the License.
// +k8s:defaulter-gen=TypeMeta
// +groupName=karpenter.k8s.aws
package v1beta1 // doc.go is discovered by codegen

import (
"github.com/aws/karpenter-provider-aws/pkg/apis"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
)

func init() {
gv := schema.GroupVersion{Group: apis.Group, Version: "v1beta1"}
v1.AddToGroupVersion(scheme.Scheme, gv)
scheme.Scheme.AddKnownTypes(gv,
&EC2NodeClass{},
&EC2NodeClassList{},
)
}
57 changes: 29 additions & 28 deletions pkg/apis/v1beta1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"fmt"
"regexp"

"github.com/aws/karpenter-provider-aws/pkg/apis"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"

coreapis "sigs.k8s.io/karpenter/pkg/apis"
"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
)

Expand Down Expand Up @@ -52,7 +53,7 @@ func init() {
}

var (
TerminationFinalizer = Group + "/termination"
TerminationFinalizer = apis.Group + "/termination"
AWSToKubeArchitectures = map[string]string{
"x86_64": v1beta1.ArchitectureAmd64,
v1beta1.ArchitectureArm64: v1beta1.ArchitectureArm64,
Expand All @@ -62,7 +63,7 @@ var (
v1beta1.ArchitectureArm64,
)
RestrictedLabelDomains = []string{
Group,
apis.Group,
}
RestrictedTagPatterns = []*regexp.Regexp{
// Adheres to cluster name pattern matching as specified in the API spec
Expand Down Expand Up @@ -93,34 +94,34 @@ var (
ResourcePrivateIPv4Address v1.ResourceName = "vpc.amazonaws.com/PrivateIPv4Address"
ResourceEFA v1.ResourceName = "vpc.amazonaws.com/efa"

LabelNodeClass = Group + "/ec2nodeclass"
LabelNodeClass = apis.Group + "/ec2nodeclass"

LabelTopologyZoneID = "topology.k8s.aws/zone-id"

LabelInstanceHypervisor = Group + "/instance-hypervisor"
LabelInstanceEncryptionInTransitSupported = Group + "/instance-encryption-in-transit-supported"
LabelInstanceCategory = Group + "/instance-category"
LabelInstanceFamily = Group + "/instance-family"
LabelInstanceGeneration = Group + "/instance-generation"
LabelInstanceLocalNVME = Group + "/instance-local-nvme"
LabelInstanceSize = Group + "/instance-size"
LabelInstanceCPU = Group + "/instance-cpu"
LabelInstanceCPUManufacturer = Group + "/instance-cpu-manufacturer"
LabelInstanceMemory = Group + "/instance-memory"
LabelInstanceEBSBandwidth = Group + "/instance-ebs-bandwidth"
LabelInstanceNetworkBandwidth = Group + "/instance-network-bandwidth"
LabelInstanceGPUName = Group + "/instance-gpu-name"
LabelInstanceGPUManufacturer = Group + "/instance-gpu-manufacturer"
LabelInstanceGPUCount = Group + "/instance-gpu-count"
LabelInstanceGPUMemory = Group + "/instance-gpu-memory"
LabelInstanceAcceleratorName = Group + "/instance-accelerator-name"
LabelInstanceAcceleratorManufacturer = Group + "/instance-accelerator-manufacturer"
LabelInstanceAcceleratorCount = Group + "/instance-accelerator-count"
AnnotationEC2NodeClassHash = Group + "/ec2nodeclass-hash"
AnnotationEC2NodeClassHashVersion = Group + "/ec2nodeclass-hash-version"
AnnotationInstanceTagged = Group + "/tagged"
LabelInstanceHypervisor = apis.Group + "/instance-hypervisor"
LabelInstanceEncryptionInTransitSupported = apis.Group + "/instance-encryption-in-transit-supported"
LabelInstanceCategory = apis.Group + "/instance-category"
LabelInstanceFamily = apis.Group + "/instance-family"
LabelInstanceGeneration = apis.Group + "/instance-generation"
LabelInstanceLocalNVME = apis.Group + "/instance-local-nvme"
LabelInstanceSize = apis.Group + "/instance-size"
LabelInstanceCPU = apis.Group + "/instance-cpu"
LabelInstanceCPUManufacturer = apis.Group + "/instance-cpu-manufacturer"
LabelInstanceMemory = apis.Group + "/instance-memory"
LabelInstanceEBSBandwidth = apis.Group + "/instance-ebs-bandwidth"
LabelInstanceNetworkBandwidth = apis.Group + "/instance-network-bandwidth"
LabelInstanceGPUName = apis.Group + "/instance-gpu-name"
LabelInstanceGPUManufacturer = apis.Group + "/instance-gpu-manufacturer"
LabelInstanceGPUCount = apis.Group + "/instance-gpu-count"
LabelInstanceGPUMemory = apis.Group + "/instance-gpu-memory"
LabelInstanceAcceleratorName = apis.Group + "/instance-accelerator-name"
LabelInstanceAcceleratorManufacturer = apis.Group + "/instance-accelerator-manufacturer"
LabelInstanceAcceleratorCount = apis.Group + "/instance-accelerator-count"
AnnotationEC2NodeClassHash = apis.Group + "/ec2nodeclass-hash"
AnnotationEC2NodeClassHashVersion = apis.Group + "/ec2nodeclass-hash-version"
AnnotationInstanceTagged = apis.Group + "/tagged"

TagNodeClaim = v1beta1.Group + "/nodeclaim"
TagManagedLaunchTemplate = Group + "/cluster"
TagNodeClaim = coreapis.Group + "/nodeclaim"
TagManagedLaunchTemplate = apis.Group + "/cluster"
TagName = "Name"
)
Loading

0 comments on commit d37e5a2

Please sign in to comment.