Sitelet https://github.com/kubernetes/kops/pull/18700/files
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions upup/pkg/fi/cloudup/linode/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type LinodeClient interface {
UpdateInstance(ctx context.Context, instanceID int, opts linodego.InstanceUpdateOptions) (*linodego.Instance, error)
DeleteInstance(ctx context.Context, instanceID int) error
ListInterfaces(ctx context.Context, instanceID int, opts *linodego.ListOptions) ([]linodego.LinodeInterface, error)
CreateVolume(ctx context.Context, opts linodego.VolumeCreateOptions) (*linodego.Volume, error)
ListVolumes(ctx context.Context, opts *linodego.ListOptions) ([]linodego.Volume, error)
// TODO(moshevayner): Add DeleteVolume and UpdateVolume/ResizeVolume methods to support volume deletion, update and resizing.
}

// LinodeCloud exposes Akamai (Linode) cloud APIs used by kOps.
Expand Down
31 changes: 31 additions & 0 deletions upup/pkg/fi/cloudup/linode/mock_linode_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ type MockLinodeClient struct {
ListInterfacesCalls int
LastListInterfacesOpts *linodego.ListOptions
LastListInterfacesID int

ListVolumesResponse []linodego.Volume
ListVolumesError error
ListVolumesCalls int
LastListVolumesOpts *linodego.ListOptions

CreateVolumeResponse *linodego.Volume
CreateVolumeError error
CreateVolumeCalls int
LastCreateVolumeOpts linodego.VolumeCreateOptions
}

var _ LinodeClient = &MockLinodeClient{}
Expand Down Expand Up @@ -336,3 +346,24 @@ func (c *MockLinodeClient) ListInterfaces(ctx context.Context, instanceID int, o
}
return c.ListInterfacesResponse, nil
}

func (c *MockLinodeClient) CreateVolume(ctx context.Context, opts linodego.VolumeCreateOptions) (*linodego.Volume, error) {
c.CreateVolumeCalls++
c.LastCreateVolumeOpts = opts
if c.CreateVolumeError != nil {
return nil, c.CreateVolumeError
}
if c.CreateVolumeResponse == nil {
return &linodego.Volume{}, nil
}
return c.CreateVolumeResponse, nil
}

func (c *MockLinodeClient) ListVolumes(ctx context.Context, opts *linodego.ListOptions) ([]linodego.Volume, error) {
c.ListVolumesCalls++
c.LastListVolumesOpts = opts
if c.ListVolumesError != nil {
return nil, c.ListVolumesError
}
return c.ListVolumesResponse, nil
}
142 changes: 142 additions & 0 deletions upup/pkg/fi/cloudup/linodetasks/volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
Copyright 2026 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 linodetasks

import (
"context"
"fmt"

"github.com/linode/linodego/v2"
"k8s.io/klog/v2"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/linode"
)

// +kops:fitask
type Volume struct {
Name *string
ID *int
Lifecycle fi.Lifecycle
Region *string
SizeGB *int
Tags []string
}

var _ fi.CloudupTask = &Volume{}
var _ fi.CompareWithID = &Volume{}

func (v *Volume) CompareWithID() *string {
return v.Name
}

func (v *Volume) Find(c *fi.CloudupContext) (*Volume, error) {
cloud := c.T.Cloud.(linode.LinodeCloud)
name := fi.ValueOf(v.Name)
if name == "" {
return nil, fmt.Errorf("Volume.Name is required")
}
listOptions, err := linode.ListOptionsForLabel(name)
if err != nil {
return nil, err
}

volumes, err := cloud.Client().ListVolumes(c.Context(), listOptions)
if err != nil {
return nil, fmt.Errorf("error listing Akamai (Linode) volumes: %w", err)
}

if len(volumes) == 0 {
return nil, nil
}

// Name is unique, so we should only have one match
matched := volumes[0]

actual := &Volume{
ID: new(matched.ID),
Name: new(matched.Label),
Lifecycle: v.Lifecycle,
Region: new(matched.Region),
SizeGB: new(matched.Size),
Tags: matched.Tags,
}
v.ID = actual.ID

return actual, nil
}

func (v *Volume) Run(c *fi.CloudupContext) error {
return fi.CloudupDefaultDeltaRunMethod(v, c)
}

func (_ *Volume) CheckChanges(actual, expected, changes *Volume) error {
if actual != nil {
if changes.ID != nil {
return fi.CannotChangeField("ID")
}
if changes.Name != nil {
return fi.CannotChangeField("Name")
}
if changes.Region != nil {
return fi.CannotChangeField("Region")
}
// TODO(moshevayner): Add support for resizing a volume.
if changes.SizeGB != nil {
return fi.CannotChangeField("SizeGB")
}
if changes.Tags != nil {
return fi.CannotChangeField("Tags")
}
} else {
if expected.Name == nil {
return fi.RequiredField("Name")
}
if expected.Region == nil {
return fi.RequiredField("Region")
}
if expected.SizeGB == nil {
return fi.RequiredField("SizeGB")
}
if fi.ValueOf(expected.SizeGB) < 10 {
return fmt.Errorf("SizeGB must be at least 10 GB")
}
}

return nil
}

func (*Volume) RenderLinode(t *linode.APITarget, actual, expected, changes *Volume) error {
if actual != nil {
return nil
}

name := fi.ValueOf(expected.Name)
created, err := t.Cloud.Client().CreateVolume(context.Background(), linodego.VolumeCreateOptions{
Label: name,
Region: fi.ValueOf(expected.Region),
Size: fi.ValueOf(expected.SizeGB),
Tags: expected.Tags,
})
if err != nil {
return fmt.Errorf("error creating Akamai (Linode) volume %q: %w", name, err)
}

expected.ID = new(created.ID)
klog.V(2).Infof("Created Akamai (Linode) volume %q (id=%d)", created.Label, created.ID)

return nil
}
52 changes: 52 additions & 0 deletions upup/pkg/fi/cloudup/linodetasks/volume_fitask.go

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

Loading
Loading