Skip to content

Commit

Permalink
Merge branch 'main' into key-secret-tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
bcm820 committed Aug 21, 2024
2 parents 8579ade + 3a074f0 commit 159bf1c
Show file tree
Hide file tree
Showing 46 changed files with 1,511 additions and 1,686 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func Convert_v1alpha2_LinodeMachineSpec_To_v1alpha1_LinodeMachineSpec(in *infras
return autoConvert_v1alpha2_LinodeMachineSpec_To_v1alpha1_LinodeMachineSpec(in, out, s)
}

func Convert_v1alpha1_LinodeMachineSpec_To_v1alpha2_LinodeMachineSpec(in *LinodeMachineSpec, out *infrastructurev1alpha2.LinodeMachineSpec, s conversion.Scope) error {
return autoConvert_v1alpha1_LinodeMachineSpec_To_v1alpha2_LinodeMachineSpec(in, out, s)
}

func Convert_v1alpha1_LinodeObjectStorageBucketSpec_To_v1alpha2_LinodeObjectStorageBucketSpec(in *LinodeObjectStorageBucketSpec, out *infrastructurev1alpha2.LinodeObjectStorageBucketSpec, s conversion.Scope) error {
// WARNING: in.Cluster requires manual conversion: does not exist in peer-type
out.Region = in.Cluster
Expand Down
8 changes: 0 additions & 8 deletions api/v1alpha1/linodemachine_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestLinodeMachineConvertTo(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "test-machine"},
Spec: LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand All @@ -53,7 +52,6 @@ func TestLinodeMachineConvertTo(t *testing.T) {
BackupsEnabled: false,
PrivateIP: ptr.To(true),
Tags: []string{"test instance"},
FirewallID: 123,
OSDisk: ptr.To(InstanceDisk{
DiskID: 0,
Size: *resource.NewQuantity(12, resource.DecimalSI),
Expand Down Expand Up @@ -83,7 +81,6 @@ func TestLinodeMachineConvertTo(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "test-machine"},
Spec: infrav1alpha2.LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand All @@ -96,7 +93,6 @@ func TestLinodeMachineConvertTo(t *testing.T) {
BackupsEnabled: false,
PrivateIP: ptr.To(true),
Tags: []string{"test instance"},
FirewallID: 123,
OSDisk: ptr.To(infrav1alpha2.InstanceDisk{
DiskID: 0,
Size: *resource.NewQuantity(12, resource.DecimalSI),
Expand Down Expand Up @@ -170,7 +166,6 @@ func TestLinodeMachineConvertFrom(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "test-machine"},
Spec: infrav1alpha2.LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand All @@ -183,7 +178,6 @@ func TestLinodeMachineConvertFrom(t *testing.T) {
BackupsEnabled: false,
PrivateIP: ptr.To(true),
Tags: []string{"test instance"},
FirewallID: 123,
OSDisk: ptr.To(infrav1alpha2.InstanceDisk{
DiskID: 0,
Size: *resource.NewQuantity(12, resource.DecimalSI),
Expand Down Expand Up @@ -218,7 +212,6 @@ func TestLinodeMachineConvertFrom(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "test-machine"},
Spec: LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand All @@ -231,7 +224,6 @@ func TestLinodeMachineConvertFrom(t *testing.T) {
BackupsEnabled: false,
PrivateIP: ptr.To(true),
Tags: []string{"test instance"},
FirewallID: 123,
OSDisk: ptr.To(InstanceDisk{
DiskID: 0,
Size: *resource.NewQuantity(12, resource.DecimalSI),
Expand Down
8 changes: 0 additions & 8 deletions api/v1alpha1/linodemachinetemplate_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func TestLinodeMachineTemplateConvertTo(t *testing.T) {
Template: LinodeMachineTemplateResource{
Spec: LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand All @@ -55,7 +54,6 @@ func TestLinodeMachineTemplateConvertTo(t *testing.T) {
BackupsEnabled: false,
PrivateIP: ptr.To(true),
Tags: []string{"test instance"},
FirewallID: 123,
OSDisk: ptr.To(InstanceDisk{
DiskID: 0,
Size: *resource.NewQuantity(12, resource.DecimalSI),
Expand Down Expand Up @@ -88,7 +86,6 @@ func TestLinodeMachineTemplateConvertTo(t *testing.T) {
Template: infrav1alpha2.LinodeMachineTemplateResource{
Spec: infrav1alpha2.LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand All @@ -101,7 +98,6 @@ func TestLinodeMachineTemplateConvertTo(t *testing.T) {
BackupsEnabled: false,
PrivateIP: ptr.To(true),
Tags: []string{"test instance"},
FirewallID: 123,
OSDisk: ptr.To(infrav1alpha2.InstanceDisk{
DiskID: 0,
Size: *resource.NewQuantity(12, resource.DecimalSI),
Expand Down Expand Up @@ -178,7 +174,6 @@ func TestLinodeMachineTemplateConvertFrom(t *testing.T) {
Template: infrav1alpha2.LinodeMachineTemplateResource{
Spec: infrav1alpha2.LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand All @@ -191,7 +186,6 @@ func TestLinodeMachineTemplateConvertFrom(t *testing.T) {
BackupsEnabled: false,
PrivateIP: ptr.To(true),
Tags: []string{"test instance"},
FirewallID: 123,
OSDisk: ptr.To(infrav1alpha2.InstanceDisk{
DiskID: 0,
Size: *resource.NewQuantity(12, resource.DecimalSI),
Expand Down Expand Up @@ -224,7 +218,6 @@ func TestLinodeMachineTemplateConvertFrom(t *testing.T) {
Template: LinodeMachineTemplateResource{
Spec: LinodeMachineSpec{
ProviderID: ptr.To("linode://1234"),
InstanceID: ptr.To(1234),
Region: "us-mia",
Type: "g6-standard-2",
Group: "",
Expand All @@ -237,7 +230,6 @@ func TestLinodeMachineTemplateConvertFrom(t *testing.T) {
BackupsEnabled: false,
PrivateIP: ptr.To(true),
Tags: []string{"test instance"},
FirewallID: 123,
OSDisk: ptr.To(InstanceDisk{
DiskID: 0,
Size: *resource.NewQuantity(12, resource.DecimalSI),
Expand Down
16 changes: 6 additions & 10 deletions api/v1alpha1/zz_generated.conversion.go

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

8 changes: 7 additions & 1 deletion api/v1alpha2/linodemachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type LinodeMachineSpec struct {
ProviderID *string `json:"providerID,omitempty"`
// InstanceID is the Linode instance ID for this machine.
// +optional
// +kubebuilder:deprecatedversion:warning="ProviderID deprecates InstanceID"
InstanceID *int `json:"instanceID,omitempty"`

// +kubebuilder:validation:Required
Expand Down Expand Up @@ -67,6 +68,7 @@ type LinodeMachineSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
Tags []string `json:"tags,omitempty"`
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:deprecatedversion:warning="Firewalls should be referenced via FirewallRef"
FirewallID int `json:"firewallID,omitempty"`
// OSDisk is configuration for the root disk that includes the OS,
// if not specified this defaults to whatever space is not taken up by the DataDisks
Expand Down Expand Up @@ -96,6 +98,10 @@ type LinodeMachineSpec struct {
// +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"`
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
// FirewallRef is a reference to a firewall object. This makes the linode use the specified firewall.
FirewallRef *corev1.ObjectReference `json:"firewallRef,omitempty"`
}

// InstanceDisk defines a list of disks to use for an instance
Expand Down Expand Up @@ -210,7 +216,7 @@ type LinodeMachineStatus struct {
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this LinodeMachine belongs"
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.instanceState",description="Linode instance state"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Machine ready status"
// +kubebuilder:printcolumn:name="InstanceID",type="string",JSONPath=".spec.providerID",description="Linode instance ID"
// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="Provider ID"
// +kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this LinodeMachine"

// LinodeMachine is the Schema for the linodemachines API
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.

1 change: 1 addition & 0 deletions clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type LinodeVPCClient interface {
type LinodeNodeBalancerClient interface {
CreateNodeBalancer(ctx context.Context, opts linodego.NodeBalancerCreateOptions) (*linodego.NodeBalancer, error)
GetNodeBalancer(ctx context.Context, nodebalancerID int) (*linodego.NodeBalancer, error)
ListNodeBalancerNodes(ctx context.Context, nodebalancerID int, configID int, opts *linodego.ListOptions) ([]linodego.NodeBalancerNode, error)
GetNodeBalancerConfig(ctx context.Context, nodebalancerID int, configID int) (*linodego.NodeBalancerConfig, error)
CreateNodeBalancerConfig(ctx context.Context, nodebalancerID int, opts linodego.NodeBalancerConfigCreateOptions) (*linodego.NodeBalancerConfig, error)
DeleteNodeBalancerNode(ctx context.Context, nodebalancerID int, configID int, nodeID int) error
Expand Down
49 changes: 35 additions & 14 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import (

// ClusterScopeParams defines the input parameters used to create a new Scope.
type ClusterScopeParams struct {
Client K8sClient
Cluster *clusterv1.Cluster
LinodeCluster *infrav1alpha2.LinodeCluster
Client K8sClient
Cluster *clusterv1.Cluster
LinodeCluster *infrav1alpha2.LinodeCluster
LinodeMachineList infrav1alpha2.LinodeMachineList
}

func validateClusterScopeParams(params ClusterScopeParams) error {
Expand All @@ -50,7 +51,7 @@ func validateClusterScopeParams(params ClusterScopeParams) error {

// NewClusterScope creates a new Scope from the supplied parameters.
// This is meant to be called for each reconcile iteration.
func NewClusterScope(ctx context.Context, linodeClientConfig ClientConfig, params ClusterScopeParams) (*ClusterScope, error) {
func NewClusterScope(ctx context.Context, linodeClientConfig, dnsClientConfig ClientConfig, params ClusterScopeParams) (*ClusterScope, error) {
if err := validateClusterScopeParams(params); err != nil {
return nil, err
}
Expand All @@ -63,6 +64,11 @@ func NewClusterScope(ctx context.Context, linodeClientConfig ClientConfig, param
return nil, fmt.Errorf("credentials from secret ref: %w", err)
}
linodeClientConfig.Token = string(apiToken)
dnsToken, err := getCredentialDataFromRef(ctx, params.Client, *params.LinodeCluster.Spec.CredentialsRef, params.LinodeCluster.GetNamespace(), "dnsToken")
if err != nil || len(dnsToken) == 0 {
dnsToken = apiToken
}
dnsClientConfig.Token = string(dnsToken)
}
linodeClient, err := CreateLinodeClient(linodeClientConfig)
if err != nil {
Expand All @@ -74,22 +80,37 @@ func NewClusterScope(ctx context.Context, linodeClientConfig ClientConfig, param
return nil, fmt.Errorf("failed to init patch helper: %w", err)
}

akamDomainsClient, err := setUpEdgeDNSInterface()
if err != nil {
return nil, fmt.Errorf("failed to create akamai dns client: %w", err)
}
linodeDomainsClient, err := CreateLinodeClient(dnsClientConfig, WithRetryCount(0))
if err != nil {
return nil, fmt.Errorf("failed to create linode client: %w", err)
}

return &ClusterScope{
Client: params.Client,
Cluster: params.Cluster,
LinodeClient: linodeClient,
LinodeCluster: params.LinodeCluster,
PatchHelper: helper,
Client: params.Client,
Cluster: params.Cluster,
LinodeClient: linodeClient,
LinodeDomainsClient: linodeDomainsClient,
AkamaiDomainsClient: akamDomainsClient,
LinodeCluster: params.LinodeCluster,
LinodeMachines: params.LinodeMachineList,
PatchHelper: helper,
}, nil
}

// ClusterScope defines the basic context for an actuator to operate upon.
type ClusterScope struct {
Client K8sClient
PatchHelper *patch.Helper
LinodeClient LinodeClient
Cluster *clusterv1.Cluster
LinodeCluster *infrav1alpha2.LinodeCluster
Client K8sClient
PatchHelper *patch.Helper
LinodeClient LinodeClient
Cluster *clusterv1.Cluster
LinodeCluster *infrav1alpha2.LinodeCluster
LinodeMachines infrav1alpha2.LinodeMachineList
AkamaiDomainsClient AkamClient
LinodeDomainsClient LinodeClient
}

// PatchObject persists the cluster configuration and status.
Expand Down
Loading

0 comments on commit 159bf1c

Please sign in to comment.