Skip to content

Commit e7cbb52

Browse files
committed
add support for additional linode envs
1 parent 17b2bcd commit e7cbb52

File tree

10 files changed

+28
-53
lines changed

10 files changed

+28
-53
lines changed

Tiltfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ k8s_resource(
1616
"container-object-storage-controller:clusterrolebinding",
1717
])
1818
namespace_create("linode-cosi-driver")
19+
args = ["apiToken=" + os.getenv("LINODE_TOKEN")]
20+
if os.getenv("LINODE_URL"):
21+
args.append("linodeApiUrl=" + os.getenv("LINODE_URL"))
22+
1923
k8s_yaml(helm( "./helm/linode-cosi-driver",
2024
"linode-cosi-driver",
2125
namespace="linode-cosi-driver",
22-
set=["apiToken=" + os.getenv("LINODE_TOKEN")],
26+
set=args,
2327
))
2428

2529
k8s_resource(

cmd/linode-cosi-driver/main.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ import (
4545
)
4646

4747
const (
48-
driverName = "objectstorage.cosi.linode.com"
49-
gracePeriod = 5 * time.Second
50-
envK8sNodeName = "K8S_NODE_NAME"
51-
envK8sPodName = "K8S_POD_NAME"
48+
driverName = "objectstorage.cosi.linode.com"
49+
gracePeriod = 5 * time.Second
5250
)
5351

5452
var ErrNoKeySpecified = errors.New("no S3 policy credentials, " +
@@ -57,9 +55,6 @@ var ErrNoKeySpecified = errors.New("no S3 policy credentials, " +
5755

5856
func main() {
5957
var (
60-
linodeToken = envflag.String("LINODE_TOKEN", "")
61-
linodeURL = envflag.String("LINODE_API_URL", "")
62-
linodeAPIVersion = envflag.String("LINODE_API_VERSION", "")
6358
cosiEndpoint = envflag.String("COSI_ENDPOINT", "unix:///var/lib/cosi/cosi.sock")
6459
cacheTTL = envflag.Duration("LINODE_OBJECT_STORAGE_ENDPOINT_CACHE_TTL", cache.DefaultTTL)
6560
s3SSL = envflag.Bool("S3_CLIENT_SSL_ENABLED", true)
@@ -73,9 +68,6 @@ func main() {
7368

7469
if err := run(context.Background(), log, mainOptions{
7570
cosiEndpoint: cosiEndpoint,
76-
linodeToken: linodeToken,
77-
linodeURL: linodeURL,
78-
linodeAPIVersion: linodeAPIVersion,
7971
cacheTTL: cacheTTL,
8072
s3SSL: s3SSL,
8173
s3EphemeralCredentials: s3EphemeralCredentials,
@@ -90,9 +82,6 @@ func main() {
9082

9183
type mainOptions struct {
9284
cosiEndpoint string
93-
linodeToken string
94-
linodeURL string
95-
linodeAPIVersion string
9685
cacheTTL time.Duration
9786
s3SSL bool
9887
s3EphemeralCredentials bool
@@ -120,11 +109,7 @@ func run(ctx context.Context, log *slog.Logger, opts mainOptions) error {
120109
}
121110

122111
// initialize Linode client
123-
client, err := linodeclient.NewLinodeClient(
124-
opts.linodeToken,
125-
fmt.Sprintf("LinodeCOSI/%s", version.Version),
126-
opts.linodeURL,
127-
opts.linodeAPIVersion)
112+
client, err := linodeclient.NewLinodeClient(fmt.Sprintf("LinodeCOSI/%s", version.Version))
128113
if err != nil {
129114
return fmt.Errorf("unable to create new client: %w", err)
130115
}

cmd/linode-cosi-driver/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func TestRun(t *testing.T) {
4646
t.Run(tc.testName, func(t *testing.T) {
4747
t.Parallel()
4848

49+
os.Setenv("LINODE_TOKEN", "test")
4950
noopLog := slog.New(slog.NewTextHandler(
5051
io.Discard,
5152
&slog.HandlerOptions{Level: slog.LevelError},

examples/linode-objectstorage.BucketClass.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
driverName: objectstorage.cosi.linode.com
66
deletionPolicy: Delete
77
parameters:
8-
cosi.linode.com/v1/region: us-east
8+
cosi.linode.com/v1/region: us-ord
99
cosi.linode.com/v1/acl: private
1010
cosi.linode.com/v1/cors: disabled
1111
cosi.linode.com/v1/policy: |-

helm/linode-cosi-driver/templates/Secret.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: Opaque
1515
data:
1616
LINODE_TOKEN: {{ required "value 'apiToken' required" .Values.apiToken | b64enc }}
1717
{{- if .Values.linodeApiUrl }}
18-
LINODE_API_URL: {{ .Values.linodeApiUrl | b64enc }}
18+
LINODE_URL: {{ .Values.linodeApiUrl | b64enc }}
1919
{{- end }}
2020
{{- if .Values.linodeApiVersion }}
2121
LINODE_API_VERSION: {{ .Values.linodeApiVersion | b64enc }}

pkg/linodeclient/linodeclient.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,18 @@ type Client interface {
4141
ListObjectStorageEndpoints(context.Context, *linodego.ListOptions) ([]linodego.ObjectStorageEndpoint, error)
4242
}
4343

44-
// NewLinodeClient takes token, userAgent prefix, and API URL and after initial validation
44+
// NewLinodeClient takes userAgent prefix after initial validation
4545
// returns new linodego Client. The client uses linodego built-in http client
4646
// which supports setting root CA cert.
47-
func NewLinodeClient(token, ua, apiURL, apiVersion string) (*linodego.Client, error) {
48-
linodeClient := linodego.NewClient(nil)
49-
linodeClient.SetUserAgent(ua)
50-
linodeClient.SetToken(token)
51-
52-
if apiURL != "" {
53-
linodeClient.SetBaseURL(apiURL)
47+
func NewLinodeClient(ua string) (*linodego.Client, error) {
48+
linodeClient, err := linodego.NewClientFromEnv(nil)
49+
if err != nil {
50+
return nil, fmt.Errorf("failed to create linode client from env: %w", err)
5451
}
5552

56-
if apiVersion != "" {
57-
linodeClient.SetAPIVersion(apiVersion)
58-
}
53+
linodeClient.SetUserAgent(ua)
5954

60-
return &linodeClient, nil
55+
return linodeClient, nil
6156
}
6257

6358
func NewEphemeralS3Credentials(

pkg/linodeclient/linodeclient_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package linodeclient
1616

1717
import (
1818
"errors"
19+
"os"
1920
"testing"
2021
)
2122

@@ -33,14 +34,6 @@ func TestNewLinodeClient(t *testing.T) {
3334
{
3435
testName: "simple",
3536
},
36-
{
37-
testName: "with user agent",
38-
userAgent: "test_UA",
39-
},
40-
{
41-
testName: "with token",
42-
token: "test_TOKEN",
43-
},
4437
{
4538
testName: "with URL",
4639
url: "https://example.com",
@@ -72,8 +65,11 @@ func TestNewLinodeClient(t *testing.T) {
7265

7366
t.Run(tc.testName, func(t *testing.T) {
7467
t.Parallel()
68+
os.Setenv("LINODE_TOKEN", "TEST_TOKEN")
69+
os.Setenv("LINODE_URL", tc.url)
70+
os.Setenv("LINODE_API_VERSION", tc.version)
7571

76-
_, err := NewLinodeClient(tc.token, tc.userAgent, tc.url, tc.version)
72+
_, err := NewLinodeClient(tc.userAgent)
7773
if !errors.Is(err, tc.expectedError) {
7874
t.Errorf("expected error: %v, but got: %v", tc.expectedError, err)
7975
}

pkg/servers/provisioner/provisionerintegration_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,16 @@ func TestHappyPath(t *testing.T) {
4444
t.Parallel()
4545

4646
var (
47-
linodeToken = envflag.String("LINODE_TOKEN", "")
48-
linodeURL = envflag.String("LINODE_API_URL", "")
49-
linodeAPIVersion = envflag.String("LINODE_API_VERSION", "")
50-
iterations = envflag.Int("IDEMPOTENCY_ITERATIONS", 2)
47+
linodeToken = envflag.String("LINODE_TOKEN", "")
48+
iterations = envflag.Int("IDEMPOTENCY_ITERATIONS", 2)
5149
)
5250

5351
if linodeToken == "" {
5452
t.Errorf("LINODE_TOKEN not set")
5553
return
5654
}
5755

58-
client, err := linodeclient.NewLinodeClient(
59-
linodeToken,
60-
fmt.Sprintf("LinodeCOSI/%s+integration", version.Version),
61-
linodeURL,
62-
linodeAPIVersion)
56+
client, err := linodeclient.NewLinodeClient(fmt.Sprintf("LinodeCOSI/%s+integration", version.Version))
6357
if err != nil {
6458
t.Errorf("failed to create client: %v", err.Error())
6559
return

test/e2e/cosi/chainsaw-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ spec:
2929
driverName: objectstorage.cosi.linode.com
3030
deletionPolicy: Delete
3131
parameters:
32-
cosi.linode.com/v1/region: us-east
32+
cosi.linode.com/v1/region: us-ord
3333
cosi.linode.com/v1/acl: private
3434
cosi.linode.com/v1/cors: disabled
3535
- apply:

test/e2e/sample-app/resources/bucketclass-apply.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
driverName: objectstorage.cosi.linode.com
66
deletionPolicy: Delete
77
parameters:
8-
cosi.linode.com/v1/region: us-east
8+
cosi.linode.com/v1/region: us-ord
99
cosi.linode.com/v1/policy: |-
1010
{
1111
"Version": "2012-10-17",

0 commit comments

Comments
 (0)