Skip to content

Commit ce7c64c

Browse files
feat: initial implementation (WIP)
TODO: - tests - integration tests Signed-off-by: Mateusz Urbanek <[email protected]>
1 parent 9523be9 commit ce7c64c

File tree

10 files changed

+337
-26
lines changed

10 files changed

+337
-26
lines changed

cmd/linode-cosi-driver/main.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ import (
2727
"syscall"
2828
"time"
2929

30+
"github.com/go-logr/logr"
3031
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
3132
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery"
3233
"github.com/linode/linode-cosi-driver/pkg/endpoint"
3334
"github.com/linode/linode-cosi-driver/pkg/envflag"
3435
"github.com/linode/linode-cosi-driver/pkg/grpc/handlers"
3536
grpclogger "github.com/linode/linode-cosi-driver/pkg/grpc/logger"
37+
"github.com/linode/linode-cosi-driver/pkg/kubereader/tracedkubereader"
3638
"github.com/linode/linode-cosi-driver/pkg/linodeclient"
3739
"github.com/linode/linode-cosi-driver/pkg/linodeclient/tracedclient"
3840
maxprocslogger "github.com/linode/linode-cosi-driver/pkg/maxprocs/logger"
@@ -47,7 +49,11 @@ import (
4749
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
4850
"go.uber.org/automaxprocs/maxprocs"
4951
"google.golang.org/grpc"
52+
v1 "k8s.io/api/core/v1"
5053
cosi "sigs.k8s.io/container-object-storage-interface-spec"
54+
"sigs.k8s.io/controller-runtime/pkg/client"
55+
"sigs.k8s.io/controller-runtime/pkg/client/config"
56+
ctrlLog "sigs.k8s.io/controller-runtime/pkg/log"
5157
)
5258

5359
const (
@@ -67,12 +73,26 @@ func main() {
6773

6874
// TODO: any logger settup must be done here, before first log call.
6975
log := slog.Default()
76+
ctrlLog.SetLogger(logr.FromSlogHandler(log.Handler()))
77+
78+
kubeclient, err := client.New(config.GetConfigOrDie(), client.Options{
79+
Cache: &client.CacheOptions{
80+
DisableFor: []client.Object{
81+
&v1.Secret{},
82+
},
83+
},
84+
})
85+
if err != nil {
86+
slog.Error("initializing kube client failed", "error", err)
87+
os.Exit(1)
88+
}
7089

7190
if err := run(context.Background(), log, mainOptions{
7291
cosiEndpoint: cosiEndpoint,
7392
linodeToken: linodeToken,
7493
linodeURL: linodeURL,
7594
linodeAPIVersion: linodeAPIVersion,
95+
kubeclient: kubeclient,
7696
},
7797
); err != nil {
7898
slog.Error("critical failure", "error", err)
@@ -85,6 +105,7 @@ type mainOptions struct {
85105
linodeToken string
86106
linodeURL string
87107
linodeAPIVersion string
108+
kubeclient client.Client
88109
}
89110

90111
func run(ctx context.Context, log *slog.Logger, opts mainOptions) error {
@@ -112,7 +133,7 @@ func run(ctx context.Context, log *slog.Logger, opts mainOptions) error {
112133
// initialize Linode client
113134
client, err := linodeclient.NewLinodeClient(
114135
opts.linodeToken,
115-
fmt.Sprintf("LinodeCOSI/%s", version.Version),
136+
version.UserAgent(),
116137
opts.linodeURL,
117138
opts.linodeAPIVersion)
118139
if err != nil {
@@ -121,10 +142,13 @@ func run(ctx context.Context, log *slog.Logger, opts mainOptions) error {
121142

122143
client.SetLogger(restylogger.Wrap(log))
123144

145+
podName := os.Getenv(envK8sPodName)
146+
124147
// create provisioner server
125148
prvSrv, err := provisioner.New(
126149
log,
127-
tracedclient.NewClientWithTracing(client, os.Getenv(envK8sPodName)),
150+
tracedclient.NewClientWithTracing(client, podName),
151+
tracedkubereader.NewKubeReaderWithTracing(opts.kubeclient, podName),
128152
)
129153
if err != nil {
130154
return fmt.Errorf("failed to create provisioner server: %w", err)

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/linode/linode-cosi-driver
33
go 1.23.1
44

55
require (
6+
github.com/go-logr/logr v1.4.2
67
github.com/go-resty/resty/v2 v2.15.3
78
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0
89
github.com/linode/linodego v1.42.0
@@ -15,7 +16,10 @@ require (
1516
go.opentelemetry.io/otel/trace v1.31.0
1617
go.uber.org/automaxprocs v1.6.0
1718
google.golang.org/grpc v1.67.1
19+
k8s.io/api v0.31.1
20+
k8s.io/apimachinery v0.31.1
1821
sigs.k8s.io/container-object-storage-interface-spec v0.1.0
22+
sigs.k8s.io/controller-runtime v0.19.0
1923
)
2024

2125
// tools
@@ -134,7 +138,6 @@ require (
134138
github.com/go-critic/go-critic v0.11.4 // indirect
135139
github.com/go-errors/errors v1.5.1 // indirect
136140
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
137-
github.com/go-logr/logr v1.4.2 // indirect
138141
github.com/go-logr/stdr v1.2.2 // indirect
139142
github.com/go-ole/go-ole v1.2.6 // indirect
140143
github.com/go-openapi/jsonpointer v0.21.0 // indirect
@@ -392,9 +395,7 @@ require (
392395
gopkg.in/yaml.v2 v2.4.0 // indirect
393396
gopkg.in/yaml.v3 v3.0.1 // indirect
394397
honnef.co/go/tools v0.5.1 // indirect
395-
k8s.io/api v0.31.1 // indirect
396398
k8s.io/apiextensions-apiserver v0.31.1 // indirect
397-
k8s.io/apimachinery v0.31.1 // indirect
398399
k8s.io/apiserver v0.31.1 // indirect
399400
k8s.io/cli-runtime v0.31.0 // indirect
400401
k8s.io/client-go v0.31.1 // indirect
@@ -408,7 +409,6 @@ require (
408409
mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f // indirect
409410
oras.land/oras-go v1.2.5 // indirect
410411
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
411-
sigs.k8s.io/controller-runtime v0.19.0 // indirect
412412
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
413413
sigs.k8s.io/kubectl-validate v0.0.5-0.20240827210056-ce13d95db263 // indirect
414414
sigs.k8s.io/kustomize/api v0.18.0 // indirect

pkg/kubereader/resource.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2024 Akamai Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package kubereader
16+
17+
import (
18+
"sigs.k8s.io/controller-runtime/pkg/client"
19+
)
20+
21+
type KubeReader interface {
22+
client.Reader
23+
}

pkg/kubereader/tracedkubereader/tracedkubereader.gen.go

+85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/servers/provisioner/consts.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
ParamACL = "cosi.linode.com/v1/acl"
2727
ParamCORS = "cosi.linode.com/v1/cors"
2828
ParamPermissions = "cosi.linode.com/v1/permissions"
29+
ParamSecretRef = "cosi.linode.com/v1/secretRef" //nolint:gosec // this is key under which secret reference is placed
2930
)
3031

3132
type ParamCORSValue string
@@ -59,12 +60,22 @@ const (
5960
S3SecretAccessSecretKey = "accessSecretKey"
6061
)
6162

63+
const (
64+
LinodeTokenKey = "LINODE_TOKEN"
65+
LinodeAPIURLKey = "LINODE_API_URL"
66+
LinodeAPIVersionKey = "LINODE_API_VERSION"
67+
LinodeDebugKey = "LINODE_DEBUG"
68+
// LinodeCAKey = "LINODE_CA" // TODO: enable setting Linode CA from string in Linode Go.
69+
)
70+
6271
var (
63-
ErrNotFound = linodego.Error{Code: http.StatusNotFound}
64-
ErrBucketExists = errors.New("bucket exists with different parameters")
65-
ErrUnsuportedAuth = errors.New("unsupported authentication schema")
66-
ErrMissingRegion = errors.New("region was not provided")
67-
ErrUnknownPermsissions = errors.New("unknown permissions")
72+
ErrNotFound = linodego.Error{Code: http.StatusNotFound}
73+
ErrBucketExists = errors.New("bucket exists with different parameters")
74+
ErrUnsuportedAuth = errors.New("unsupported authentication schema")
75+
ErrMissingRegion = errors.New("region was not provided")
76+
ErrUnknownPermsissions = errors.New("unknown permissions")
77+
ErrInvalidSecretReference = errors.New("invalid secret reference")
78+
ErrInvalidSecret = errors.New("invalid secret")
6879
)
6980

7081
const (

0 commit comments

Comments
 (0)