Skip to content

Commit

Permalink
[feat] Add PlacementGroupRef to linodeMachine (#418)
Browse files Browse the repository at this point in the history
No flavor as of now, can be tested manually by inserting into the manifest for a cluster

---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: LinodeMachineTemplate
metadata:
  name: schinmai-test-control-plane
  namespace: default
spec:
  template:
    spec:
      authorizedKeys: null
      image: linode/ubuntu22.04
      interfaces:
      - purpose: public
      placementGroupRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
        kind: LinodePlacementGroup
        name: schinmai-test
      region: us-ord
      type: g6-standard-2
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: LinodePlacementGroup
metadata:
  name: schinmai-test
  namespace: default
spec:
  region: us-ord
---
  • Loading branch information
tchinmai7 authored Jul 28, 2024
1 parent fbb370a commit 4e620d5
Show file tree
Hide file tree
Showing 28 changed files with 410 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ on:
- linodemachine
- linodeobj
- linodevpc
# - linodeplacementgroup
- linodeplacementgroup
- all
e2e-flags:
type: string
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ func Convert_v1alpha2_NetworkSpec_To_v1alpha1_NetworkSpec(in *infrastructurev1al
out.NodeBalancerID = in.NodeBalancerID
return nil
}

func Convert_v1alpha2_LinodeMachineSpec_To_v1alpha1_LinodeMachineSpec(in *infrastructurev1alpha2.LinodeMachineSpec, out *LinodeMachineSpec, s conversion.Scope) error {
// Ok to use the auto-generated conversion function, it simply drops the PlacementGroupRef, and copies everything else
return autoConvert_v1alpha2_LinodeMachineSpec_To_v1alpha1_LinodeMachineSpec(in, out, s)
}
5 changes: 5 additions & 0 deletions api/v1alpha1/linodemachine_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ func TestLinodeMachineConvertFrom(t *testing.T) {
Namespace: "default",
Name: "cred-secret",
},
PlacementGroupRef: &corev1.ObjectReference{
Kind: "LinodePlacementGroup",
Name: "test-placement-group",
Namespace: "default",
},
},
Status: infrav1alpha2.LinodeMachineStatus{},
}
Expand Down
64 changes: 50 additions & 14 deletions api/v1alpha1/zz_generated.conversion.go

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

5 changes: 5 additions & 0 deletions api/v1alpha2/linodemachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ type LinodeMachineSpec struct {
// 3. Controller
// +optional
CredentialsRef *corev1.SecretReference `json:"credentialsRef,omitempty"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
// PlacementGroupRef is a reference to a placement group object. This makes the linode to be launched in that specific group.
PlacementGroupRef *corev1.ObjectReference `json:"placementGroupRef,omitempty"`
}

// InstanceDisk defines a list of disks to use for an instance
Expand Down
7 changes: 4 additions & 3 deletions api/v1alpha2/linodeplacementgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ type LinodePlacementGroupSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
Region string `json:"region"`
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:default=true
// +kubebuilder:default="strict"
// +kubebuilder:validation:Enum=strict;flexible
// +optional
IsStrict bool `json:"isStrict"`
PlacementGroupPolicy string `json:"placementGroupPolicy"`

// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:default="anti_affinity:local"
// +kubebuilder:validation:Enum="anti_affinity:local"
// +optional
AffinityType string `json:"affinityType"`
PlacementGroupType string `json:"placementGroupType"`
// TODO: add affinity as a type when available

// CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this PlacementGroup. If not
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha2/linodeplacementgroup_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *LinodePlacementGroup) validateLinodePlacementGroupSpec(ctx context.Cont
if err := validatePlacementGroupLabel(r.Name, field.NewPath("metadata").Child("name")); err != nil {
errs = append(errs, err)
}
// isStrict is immutable, no need to verify again.
// PlacementGroupPolicy is immutable, no need to verify again.
if len(errs) == 0 {
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,54 @@ spec:
required:
- size
type: object
placementGroupRef:
description: PlacementGroupRef is a reference to a placement group
object. This makes the linode to be launched in that specific group.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: |-
If referring to a piece of an object instead of an entire object, this string
should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within a pod, this would take on a value like:
"spec.containers{name}" (where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]" (container with
index 2 in this pod). This syntax is chosen only to have some well-defined way of
referencing a part of an object.
TODO: this design is not final and this field is subject to change in the future.
type: string
kind:
description: |-
Kind of the referent.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
namespace:
description: |-
Namespace of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
type: string
resourceVersion:
description: |-
Specific resourceVersion to which this reference is made, if any.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
type: string
uid:
description: |-
UID of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids
type: string
type: object
x-kubernetes-map-type: atomic
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
privateIP:
type: boolean
x-kubernetes-validations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,55 @@ spec:
required:
- size
type: object
placementGroupRef:
description: PlacementGroupRef is a reference to a placement
group object. This makes the linode to be launched in that
specific group.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: |-
If referring to a piece of an object instead of an entire object, this string
should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within a pod, this would take on a value like:
"spec.containers{name}" (where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]" (container with
index 2 in this pod). This syntax is chosen only to have some well-defined way of
referencing a part of an object.
TODO: this design is not final and this field is subject to change in the future.
type: string
kind:
description: |-
Kind of the referent.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
name:
description: |-
Name of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
namespace:
description: |-
Namespace of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
type: string
resourceVersion:
description: |-
Specific resourceVersion to which this reference is made, if any.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
type: string
uid:
description: |-
UID of the referent.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids
type: string
type: object
x-kubernetes-map-type: atomic
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
privateIP:
type: boolean
x-kubernetes-validations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ spec:
spec:
description: LinodePlacementGroupSpec defines the desired state of LinodePlacementGroup
properties:
affinityType:
default: anti_affinity:local
enum:
- anti_affinity:local
type: string
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
credentialsRef:
description: |-
CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this PlacementGroup. If not
Expand All @@ -74,14 +66,25 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
isStrict:
default: true
type: boolean
pgID:
type: integer
placementGroupPolicy:
default: strict
enum:
- strict
- flexible
type: string
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
placementGroupType:
default: anti_affinity:local
enum:
- anti_affinity:local
type: string
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
pgID:
type: integer
region:
type: string
x-kubernetes-validations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: CustomResourceDefinition
metadata:
name: linodeclustertemplates.infrastructure.cluster.x-k8s.io
labels:
cluster.x-k8s.io/v1beta1: v1alpha1
cluster.x-k8s.io/v1beta1: v1alpha2
2 changes: 1 addition & 1 deletion config/crd/patches/capicontract_in_linodemachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: CustomResourceDefinition
metadata:
name: linodemachines.infrastructure.cluster.x-k8s.io
labels:
cluster.x-k8s.io/v1beta1: v1alpha1
cluster.x-k8s.io/v1beta1: v1alpha2
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: CustomResourceDefinition
metadata:
name: linodemachinetemplates.infrastructure.cluster.x-k8s.io
labels:
cluster.x-k8s.io/v1beta1: v1alpha1
cluster.x-k8s.io/v1beta1: v1alpha2
2 changes: 1 addition & 1 deletion config/crd/patches/capicontract_in_linodevpcs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: CustomResourceDefinition
metadata:
name: linodevpcs.infrastructure.cluster.x-k8s.io
labels:
cluster.x-k8s.io/v1beta1: v1alpha1
cluster.x-k8s.io/v1beta1: v1alpha2
Loading

0 comments on commit 4e620d5

Please sign in to comment.