Skip to content

Commit 56fd505

Browse files
committed
Add service properties to DriverDiscovery resource
Signed-off-by: Ivan Sim <[email protected]>
1 parent 84ad1b9 commit 56fd505

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

cmd/mock/http/main.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"encoding/json"
66
"errors"
77
"flag"
8+
"fmt"
89
"net/http"
910
"os"
1011
"os/signal"
12+
"strconv"
1113
"time"
1214

1315
"github.com/ihcsim/cbt-aggapi/pkg/apis/cbt/v1alpha1"
@@ -23,8 +25,10 @@ import (
2325
"k8s.io/klog"
2426
)
2527

28+
const defaultPort = 8080
29+
2630
var (
27-
listenAddr = flag.String("listen-addr", ":8080", "Address to listen at")
31+
listenAddr = flag.String("listen-addr", fmt.Sprintf(":%d", defaultPort), "Address to listen at")
2832
grpcTarget = flag.String("grpc-target", ":9779", "Address of the GRPC server")
2933
)
3034

@@ -60,14 +64,25 @@ func registerDriver() (runtime.Object, error) {
6064
return nil, err
6165
}
6266

67+
svcPort, err := strconv.ParseInt(os.Getenv("SVC_PORT"), 10, 32)
68+
if err != nil {
69+
klog.Error(err)
70+
svcPort = defaultPort
71+
}
72+
6373
var (
6474
endpoint = &v1alpha1.DriverDiscovery{
6575
ObjectMeta: metav1.ObjectMeta{
6676
Name: os.Getenv("CSI_DRIVER_NAME"),
6777
},
6878
Spec: v1alpha1.DriverDiscoverySpec{
69-
Driver: os.Getenv("CSI_DRIVER_NAME"),
70-
CBTEndpoint: os.Getenv("CSI_CBT_ENDPOINT"),
79+
Driver: os.Getenv("CSI_DRIVER_NAME"),
80+
Service: v1alpha1.Service{
81+
Name: os.Getenv("SVC_NAME"),
82+
Namespace: os.Getenv("SVC_NAMESPACE"),
83+
Path: "/",
84+
Port: svcPort,
85+
},
7186
},
7287
}
7388
retry = time.Second * 5

pkg/apis/cbt/v1alpha1/driverdiscovery_types.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@ type DriverDiscoveryList struct {
5252

5353
// DriverDiscoverySpec defines the desired state of DriverDiscovery
5454
type DriverDiscoverySpec struct {
55-
Driver string `json:"driverName"`
56-
CBTEndpoint string `json:"cbtEndpoint"`
57-
CABundle string `json:"caBundle"`
55+
Driver string `json:"driverName"`
56+
CABundle string `json:"caBundle"`
57+
Service Service `json:"service"`
58+
}
59+
60+
type Service struct {
61+
Name string `json:"name"`
62+
Namespace string `json:"namespace"`
63+
Path string `json:"path"`
64+
Port int64 `json:"port"`
5865
}
5966

6067
var _ resource.Object = &DriverDiscovery{}

pkg/apis/cbt/v1alpha1/zz_generated.deepcopy.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yaml/mock/cbt-http.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ spec:
2727
env:
2828
- name: CSI_DRIVER_NAME
2929
value: example.csi.k8s.io
30-
- name: CSI_CBT_ENDPOINT
31-
value: http://cbt-http:8080
30+
- name: SVC_NAME
31+
value: cbt-http
32+
- name: SVC_PORT
33+
value: "8080"
34+
- name: SVC_NAMESPACE
35+
valueFrom:
36+
fieldRef:
37+
fieldPath: metadata.namespace
3238
ports:
3339
- name: http
3440
containerPort: 8080

0 commit comments

Comments
 (0)