Skip to content

Commit

Permalink
Merge branch 'main' into generalize-offering-requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
rschalo authored May 23, 2024
2 parents de6cbd1 + 0308880 commit 0d49c1e
Show file tree
Hide file tree
Showing 14 changed files with 482 additions and 35 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ apply-with-kind: verify build-with-kind ## Deploy the kwok controller from the c
apply: verify build ## Deploy the kwok controller from the current state of your git repository into your ~/.kube/config cluster
hack/validation/kwok-requirements.sh
kubectl apply -f pkg/apis/crds
kubectl apply -f kwok/apis/crds
helm upgrade --install karpenter kwok/charts --namespace $(KARPENTER_NAMESPACE) --skip-crds \
$(HELM_OPTS) \
--set controller.image.repository=$(IMG_REPOSITORY) \
Expand Down
9 changes: 8 additions & 1 deletion kwok/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ spec:
operator: In
values: ["spot"]
nodeClassRef:
name: nil
name: default
kind: KWOKNodeClass
apiVersion: v1alpha1
limits:
cpu: 1000
disruption:
consolidationPolicy: WhenUnderutilized
expireAfter: 720h # 30 * 24h = 720h
---
apiVersion: kwok.karpenter.sh/v1alpha1
kind: KWOKNodeClass
metadata:
name: default
EOF
```

Expand Down
46 changes: 46 additions & 0 deletions kwok/apis/apis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package apis

import (
_ "embed"

"github.com/samber/lo"
"k8s.io/api/node/v1alpha1"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"

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

var (
// Builder includes all types within the apis package
Builder = runtime.NewSchemeBuilder(
v1alpha1.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 (
//go:embed crds/kwok.karpenter.sh_kwoknodeclasses.yaml
KWOKNodeClassCRD []byte
CRDs = []*v1.CustomResourceDefinition{
lo.Must(functional.Unmarshal[v1.CustomResourceDefinition](KWOKNodeClassCRD)),
}
)
121 changes: 121 additions & 0 deletions kwok/apis/crds/kwok.karpenter.sh_kwoknodeclasses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
name: kwoknodeclasses.kwok.karpenter.sh
spec:
group: kwok.karpenter.sh
names:
categories:
- karpenter
kind: KWOKNodeClass
listKind: KWOKNodeClassList
plural: kwoknodeclasses
shortNames:
- kwoknc
- kwokncs
singular: kwoknodeclass
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: KWOKNodeClass is the Schema for the KWOKNodeClass API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
status:
default:
conditions:
- lastTransitionTime: "2024-01-01T01:01:01Z"
message: ""
reason: Ready
status: "True"
type: Ready
description: KwokNodeClassStatus contains the resolved state of the KwokNodeClass
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
type: object
type: object
served: true
storage: true
subresources:
status: {}
21 changes: 21 additions & 0 deletions kwok/apis/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:defaulter-gen=TypeMeta
// +groupName=kwok.karpenter.sh
package v1alpha1 // doc.go is discovered by codegen
40 changes: 40 additions & 0 deletions kwok/apis/v1alpha1/kwoknodeclass.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// KWOKNodeClass is the Schema for the KWOKNodeClass API
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=kwoknodeclasses,scope=Cluster,categories=karpenter,shortName={kwoknc,kwokncs}
// +kubebuilder:subresource:status
type KWOKNodeClass struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// +kubebuilder:default:={conditions: {{type: "Ready", status: "True", reason:"Ready", lastTransitionTime: "2024-01-01T01:01:01Z", message: ""}}}
Status KwokNodeClassStatus `json:"status,omitempty"`
}

// KWOKNodeClassList contains a list of KwokNodeClass
// +kubebuilder:object:root=true
type KWOKNodeClassList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []KWOKNodeClass `json:"items"`
}
39 changes: 39 additions & 0 deletions kwok/apis/v1alpha1/kwoknodeclass_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"github.com/awslabs/operatorpkg/status"
)

// KwokNodeClassStatus contains the resolved state of the KwokNodeClass
type KwokNodeClassStatus struct {
// Conditions contains signals for health and readiness
Conditions []status.Condition `json:"conditions,omitempty"`
}

func (in *KWOKNodeClass) StatusConditions() status.ConditionSet {
return status.NewReadyConditions().For(in)
}

func (in *KWOKNodeClass) GetConditions() []status.Condition {
return in.Status.Conditions
}

func (in *KWOKNodeClass) SetConditions(conditions []status.Condition) {
in.Status.Conditions = conditions
}
32 changes: 32 additions & 0 deletions kwok/apis/v1alpha1/labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

const (
// Labels that can be selected on and are propagated to the node
InstanceTypeLabelKey = Group + "/instance-type"
InstanceSizeLabelKey = Group + "/instance-size"
InstanceFamilyLabelKey = Group + "/instance-family"
InstanceMemoryLabelKey = Group + "/instance-memory"
InstanceCPULabelKey = Group + "/instance-cpu"

// Internal labels that are propagated to the node
KwokLabelKey = "kwok.x-k8s.io/node"
KwokLabelValue = "fake"
NodeViewerLabelKey = "eks-node-viewer/instance-price"
KwokPartitionLabelKey = "kwok-partition"
)
39 changes: 39 additions & 0 deletions kwok/apis/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

const (
Group = "kwok.karpenter.sh"
)

var (
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: "v1alpha1"}
SchemeBuilder = runtime.NewSchemeBuilder(func(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&KWOKNodeClass{},
&KWOKNodeClassList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
})
)
Loading

0 comments on commit 0d49c1e

Please sign in to comment.