8000 [Maintenance] Extract GRPC Package for compatibility (#1763) · arangodb/kube-arangodb@cce50b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit cce50b3

Browse files
authored
[Maintenance] Extract GRPC Package for compatibility (#1763)
1 parent 4462669 commit cce50b3

File tree

14 files changed

+267
-30
lines changed
  • util
  • 14 files changed

    +267
    -30
    lines changed

    .golangci.yaml

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -133,6 +133,8 @@ linters-settings:
    133133
    pkg: k8s.io/apimachinery/pkg/apis/meta/v1
    134134
    - alias: typedCore
    135135
    pkg: k8s.io/client-go/kubernetes/typed/core/v1
    136+
    - alias: ugrpc
    137+
    pkg: github.com/arangodb/kube-arangodb/pkg/util/grpc
    136138
    gci:
    137139
    sections:
    138140
    - standard

    CHANGELOG.md

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -19,6 +19,7 @@
    1919
    - (Feature) (Scheduler) Helm Driver Param
    2020
    - (Feature) (Integration) Services Endpoint
    2121
    - (Feature) (Platform) Storage
    22+
    - (Maintenance) Extract GRPC Client Package
    2223

    2324
    ## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
    2425
    - (Feature) ArangoRoute CRD
    Lines changed: 30 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,30 @@
    1+
    //
    2+
    // DISCLAIMER
    3+
    //
    4+
    // Copyright 2024 ArangoDB GmbH, Cologne, Germany
    5+
    //
    6+
    // Licensed under the Apache License, Version 2.0 (the "License");
    7+
    // you may not use this file except in compliance with the License.
    8+
    // You may obtain a copy of the License at
    9+
    //
    10+
    // http://www.apache.org/licenses/LICENSE-2.0
    11+
    //
    12+
    // Unless required by applicable law or agreed to in writing, software
    13+
    // distributed under the License is distributed on an "AS IS" BASIS,
    14+
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15+
    // See the License for the specific language governing permissions and
    16+
    // limitations under the License.
    17+
    //
    18+
    // Copyright holder is ArangoDB GmbH, Cologne, Germany
    19+
    //
    20+
    21+
    package v1
    22+
    23+
    import (
    24+
    "testing"
    25+
    )
    26+
    27+
    func Test_ServerGroupSpecVolumeMount(t *testing.T) {
    28+
    // TODO: Uncomment after upgrade to 1.31.1+
    29+
    // require.NoError(t, types.EnsureTypeForwardCompatibility(reflect.TypeOf(core.VolumeMount{}), reflect.TypeOf(ServerGroupSpecVolumeMount{})))
    30+
    }

    pkg/apis/deployment/v1/server_group_volume_mount.go

    Lines changed: 64 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,7 +1,7 @@
    11
    //
    22
    // DISCLAIMER
    33
    //
    4-
    // Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
    4+
    // Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
    55
    //
    66
    // Licensed under the Apache License, Version 2.0 (the "License");
    77
    // you may not use this file except in compliance with the License.
    @@ -55,10 +55,71 @@ func (s ServerGroupSpecVolumeMounts) Validate() error {
    5555
    return shared.WithErrors(validateErrors...)
    5656
    }
    5757

    58-
    type ServerGroupSpecVolumeMount core.VolumeMount
    58+
    type ServerGroupSpecVolumeMount struct {
    59+
    // This must match the Name of a Volume.
    60+
    Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
    61+
    // Mounted read-only if true, read-write otherwise (false or unspecified).
    62+
    // Defaults to false.
    63+
    // +optional
    64+
    65+
    ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,2,opt,name=readOnly"`
    66+
    // RecursiveReadOnly specifies whether read-only mounts should be handled
    67+
    // recursively.
    68+
    //
    69+
    // If ReadOnly is false, this field has no meaning and must be unspecified.
    70+
    //
    71+
    // If ReadOnly is true, and this field is set to Disabled, the mount is not made
    72+
    // recursively read-only. If this field is set to IfPossible, the mount is made
    73+
    // recursively read-only, if it is supported by the container runtime. If this
    74+
    // field is set to Enabled, the mount is made recursively read-only if it is
    75+
    // supported by the container runtime, otherwise the pod will not be started and
    76+
    // an error will be generated to indicate the reason.
    77+
    //
    78+
    // If this field is set to IfPossible or Enabled, MountPropagation must be set to
    79+
    // None (or be unspecified, which defaults to None).
    80+
    //
    81+
    // If this field is not specified, it is treated as an equivalent of Disabled.
    82+
    //
    83+
    // +featureGate=RecursiveReadOnlyMounts
    84+
    // +optional
    85+
    // TODO: Uncomment after upgrade to 1.31.1+
    86+
    // RecursiveReadOnly *RecursiveReadOnlyMode `json:"recursiveReadOnly,omitempty" protobuf:"bytes,7,opt,name=recursiveReadOnly,casttype=RecursiveReadOnlyMode"`
    87+
    88+
    // Path within the container at which the volume should be mounted. Must
    89+
    // not contain ':'.
    90+
    MountPath string `json:"mountPath" protobuf:"bytes,3,opt,name=mountPath"`
    91+
    // Path within the volume from which the container's volume should be mounted.
    92+
    // Defaults to "" (volume's root).
    93+
    // +optional
    94+
    95+
    SubPath string `json:"subPath,omitempty" protobuf:"bytes,4,opt,name=subPath"`
    96+
    // mountPropagation determines how mounts are propagated from the host
    97+
    // to container and the other way around.
    98+
    // When not set, MountPropagationNone is used.
    99+
    // This field is beta in 1.10.
    100+
    // When RecursiveReadOnly is set to IfPossible or to Enabled, MountPropagation must be None or unspecified
    101+
    // (which defaults to None).
    102+
    // +optional
    103+
    104+
    MountPropagation *core.MountPropagationMode `json:"mountPropagation,omitempty" protobuf:"bytes,5,opt,name=mountPropagation,casttype=MountPropagationMode"`
    105+
    // Expanded path within the volume from which the container's volume should be mounted.
    106+
    // Behaves similarly to SubPath but environment variable references $(VAR_NAME) are expanded using the container's environment.
    107+
    // Defaults to "" (volume's root).
    108+
    // SubPathExpr and SubPath are mutually exclusive.
    109+
    // +optional
    110+
    SubPathExpr string `json:"subPathExpr,omitempty" protobuf:"bytes,6,opt,name=subPathExpr"`
    111+
    }
    59112

    60113
    func (s ServerGroupSpecVolumeMount) VolumeMount() core.VolumeMount {
    61-
    return core.VolumeMount(s)
    114+
    return core.VolumeMount{
    115+
    Name: s.Name,
    116+
    ReadOnly: s.ReadOnly,
    117+
    //RecursiveReadOnly: s.RecursiveReadOnly, TODO: Uncomment after upgrade to 1.31.1+
    118+
    MountPath: s.MountPath,
    119+
    SubPath: s.SubPath,
    120+
    MountPropagation: s.MountPropagation,
    121+
    SubPathExpr: s.SubPathExpr,
    122+
    }
    62123
    }
    63124

    64125
    func (s *ServerGroupSpecVolumeMount) Validate() error {

    pkg/apis/deployment/v1/zz_generated.deepcopy.go

    Lines changed: 0 additions & 5 deletions
    Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
    Lines changed: 30 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,30 @@
    1+
    //
    2+
    // DISCLAIMER
    3+
    //
    4+
    // Copyright 2024 ArangoDB GmbH, Cologne, Germany
    5+
    //
    6+
    // Licensed under the Apache License, Version 2.0 (the "License");
    7+
    // you may not use this file except in compliance with the License.
    8+
    // You may obtain a copy of the License at
    9+
    //
    10+
    // http://www.apache.org/licenses/LICENSE-2.0
    11+
    //
    12+
    // Unless required by applicable law or agreed to in writing, software
    13+
    // distributed under the License is distributed on an "AS IS" BASIS,
    14+
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15+
    // See the License for the specific language governing permissions and
    16+
    // limitations under the License.
    17+
    //
    18+
    // Copyright holder is ArangoDB GmbH, Cologne, Germany
    19+
    //
    20+
    21+
    package v2alpha1
    22+
    23+
    import (
    24+
    "testing"
    25+
    )
    26+
    27+
    func Test_ServerGroupSpecVolumeMount(t *testing.T) {
    28+
    // TODO: Uncomment after upgrade to 1.31.1+
    29+
    // require.NoError(t, types.EnsureTypeForwardCompatibility(reflect.TypeOf(core.VolumeMount{}), reflect.TypeOf(ServerGroupSpecVolumeMount{})))
    30+
    }

    pkg/apis/deployment/v2alpha1/server_group_volume_mount.go

    Lines changed: 64 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,7 +1,7 @@
    11
    //
    22
    // DISCLAIMER
    33
    //
    4-
    // Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
    4+
    // Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
    55
    //
    66
    // Licensed under the Apache License, Version 2.0 (the "License");
    77
    // you may not use this file except in compliance with the License.
    @@ -55,10 +55,71 @@ func (s ServerGroupSpecVolumeMounts) Validate() error {
    5555
    return shared.WithErrors(validateErrors...)
    5656
    }
    5757

    58-
    type ServerGroupSpecVolumeMount core.VolumeMount
    58+
    type ServerGroupSpecVolumeMount struct {
    59+
    // This must match the Name of a Volume.
    60+
    Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
    61+
    // Mounted read-only if true, read-write otherwise (false or unspecified).
    62+
    // Defaults to false.
    63+
    // +optional
    64+
    65+
    ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,2,opt,name=readOnly"`
    66+
    // RecursiveReadOnly specifies whether read-only mounts should be handled
    67+
    // recursively.
    68+
    //
    69+
    // If ReadOnly is false, this field has no meaning and must be unspecified.
    70+
    //
    71+
    // If ReadOnly is true, and this field is set to Disabled, the mount is not made
    72+
    // recursively read-only. If this field is set to IfPossible, the mount is made
    73+
    // recursively read-only, if it is supported by the container runtime. If this
    74+
    // field is set to Enabled, the mount is made recursively read-only if it is
    75+
    // supported by the container runtime, otherwise the pod will not be started and
    76+
    // an error will be generated to indicate the reason.
    77+
    //
    78+
    // If this field is set to IfPossible or Enabled, MountPropagation must be set to
    79+
    // None (or be unspecified, which defaults to None).
    80+
    //
    81+
    // If this field is not specified, it is treated as an equivalent of Disabled.
    82+
    //
    83+
    // +featureGate=RecursiveReadOnlyMounts
    84+
    // +optional
    85+
    // TODO: Uncomment after upgrade to 1.31.1+
    86+
    // RecursiveReadOnly *RecursiveReadOnlyMode `json:"recursiveReadOnly,omitempty" protobuf:"bytes,7,opt,name=recursiveReadOnly,casttype=RecursiveReadOnlyMode"`
    87+
    88+
    // Path within the container at which the volume should be mounted. Must
    89+
    // not contain ':'.
    90+
    MountPath string `json:"mountPath" protobuf:"bytes,3,opt,name=mountPath"`
    91+
    // Path within the volume from which the container's volume should be mounted.
    92+
    // Defaults to "" (volume's root).
    93+
    // +optional
    94+
    95+
    SubPath string `json:"subPath,omitempty" protobuf:"bytes,4,opt,name=subPath"`
    96+
    // mountPropagation determines how mounts are propagated from the host
    97+
    // to container and the other way around.
    98+
    // When not set, MountPropagationNone is used.
    99+
    // This field is beta in 1.10.
    100+
    // When RecursiveReadOnly is set to IfPossible or to Enabled, MountPropagation must be None or unspecified
    101+
    // (which defaults to None).
    102+
    // +optional
    103+
    104+
    MountPropagation *core.MountPropagationMode `json:"mountPropagation,omitempty" protobuf:"bytes,5,opt,name=mountPropagation,casttype=MountPropagationMode"`
    105+
    // Expanded path within the volume from which the container's volume should be mounted.
    106+
    // Behaves similarly to SubPath but environment variable references $(VAR_NAME) are expanded using the container's environment.
    107+
    // Defaults to "" (volume's root).
    108+
    // SubPathExpr and SubPath are mutually exclusive.
    109+
    // +optional
    110+
    SubPathExpr string `json:"subPathExpr,omitempty" protobuf:"bytes,6,opt,name=subPathExpr"`
    111+
    }
    59112

    60113
    func (s ServerGroupSpecVolumeMount) VolumeMount() core.VolumeMount {
    61-
    return core.VolumeMount(s)
    114+
    return core.VolumeMount{
    115+
    Name: s.Name,
    116+
    ReadOnly: s.ReadOnly,
    117+
    //RecursiveReadOnly: s.RecursiveReadOnly, TODO: Uncomment after upgrade to 1.31.1+
    118+
    MountPath: s.MountPath,
    119+
    SubPath: s.SubPath,
    120+
    MountPropagation: s.MountPropagation,
    121+
    SubPathExpr: s.SubPathExpr,
    122+
    }
    62123
    }
    63124

    64125
    func (s *ServerGroupSpecVolumeMount) Validate() error {

    pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go

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

    pkg/integrations/auth.go

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -28,7 +28,7 @@ import (
    2828
    "google.golang.org/grpc/metadata"
    2929
    "google.golang.org/grpc/status"
    3030

    31-
    "github.com/arangodb/kube-arangodb/pkg/util"
    31+
    ugrpc "github.com/arangodb/kube-arangodb/pkg/util/grpc"
    3232
    )
    3333

    3434
    func basicTokenAuthAuthorize(ctx context.Context, token string) error {
    @@ -37,7 +37,7 @@ func basicTokenAuthAuthorize(ctx context.Context, token string) error {
    3737
    return status.Errorf(codes.Unauthenticated, "metadata is not provided")
    3838
    }
    3939

    40-
    values := md[util.AuthorizationGRPCHeader]
    40+
    values := md[ugrpc.AuthorizationGRPCHeader]
    4141
    if len(values) == 0 {
    4242
    return status.Errorf(codes.Unauthenticated, "authorization token is not provided")
    4343
    }

    pkg/integrations/clients/client.go

    Lines changed: 5 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -31,6 +31,7 @@ import (
    3131
    "google.golang.org/grpc"
    3232

    3333
    "github.com/arangodb/kube-arangodb/pkg/util"
    34+
    ugrpc "github.com/arangodb/kube-arangodb/pkg/util/grpc"
    3435
    "github.com/arangodb/kube-arangodb/pkg/util/shutdown"
    3536
    )
    3637

    @@ -74,7 +75,7 @@ func client[T any](ctx context.Context, cfg *Config, in func(cc grpc.ClientConnI
    7475
    var opts []grpc.DialOption
    7576

    7677
    if token := cfg.Token; token != "" {
    77-
    opts = append(opts, util.TokenAuthInterceptors(token)...)
    78+
    opts = append(opts, ugrpc.TokenAuthInterceptors(token)...)
    7879
    }
    7980

    8081
    if cfg.TLS.Enabled {
    @@ -99,18 +100,18 @@ func client[T any](ctx context.Context, cfg *Config, in func(cc grpc.ClientConnI
    99100
    }
    100101

    101102
    if cfg.TLS.Fallback {
    102-
    client, closer, err := util.NewOptionalTLSGRPCClient(ctx, in, cfg.Address, config, opts...)
    103+
    client, closer, err := ugrpc.NewOptionalTLSGRPCClient(ctx, in, cfg.Address, config, opts...)
    103104
    if err != nil {
    104105
    return util.Default[T](), nil, err
    105106
    }
    106107

    107108
    return client, closer, nil
    108109
    } else {
    109-
    opts = append(opts, util.ClientTLS(config)...)
    110+
    opts = append(opts, ugrpc.ClientTLS(config)...)
    110111
    }
    111112
    }
    112113

    113-
    client, closer, err := util.NewGRPCClient(ctx, in, cfg.Address, opts...)
    114+
    client, closer, err := ugrpc.NewGRPCClient(ctx, in, cfg.Address, opts...)
    114115
    if err != nil {
    115116
    return util.Default[T](), nil, err
    116117
    }

    pkg/integrations/envoy_auth_v3.go

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -27,7 +27,7 @@ import (
    2727

    2828
    pbAuthenticationV1 "github.com/arangodb/kube-arangodb/integrations/authentication/v1/definition"
    2929
    pbImplEnvoyAuthV3 "github.com/arangodb/kube-arangodb/integrations/envoy/auth/v3"
    30-
    "github.com/arangodb/kube-arangodb/pkg/util"
    30+
    ugrpc "github.com/arangodb/kube-arangodb/pkg/util/grpc"
    3131
    "github.com/arangodb/kube-arangodb/pkg/util/svc"
    3232
    )
    3333

    @@ -60,7 +60,7 @@ func (a *envoyAuthV3) Handler(ctx context.Context, cmd *cobra.Command) (svc.Hand
    6060
    return nil, err
    6161
    }
    6262

    63-
    c, _, err := util.NewGRPCClient(ctx, pbAuthenticationV1.NewAuthenticationV1Client, v)
    63+
    c, _, err := ugrpc.NewGRPCClient(ctx, pbAuthenticationV1.NewAuthenticationV1Client, v)
    6464
    if err != nil {
    6565
    return nil, err
    6666
    }

    pkg/util/grpc.go renamed to pkg/util/grpc/grpc.go

    Lines changed: 4 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,7 +18,7 @@
    1818
    // Copyright holder is ArangoDB GmbH, Cologne, Germany
    1919
    //
    2020

    21-
    package util
    21+
    package grpc
    2222

    2323
    import (
    2424
    "context"
    @@ -35,6 +35,7 @@ import (
    3535

    3636
    pbPongV1 "github.com/arangodb/kube-arangodb/integrations/pong/v1/definition"
    3737
    pbSharedV1 "github.com/arangodb/kube-arangodb/integrations/shared/v1/definition"
    38+
    "github.com/arangodb/kube-arangodb/pkg/util"
    3839
    "github.com/ara AB4B ngodb/kube-arangodb/pkg/util/svc"
    3940
    )
    4041

    @@ -43,7 +44,7 @@ const AuthorizationGRPCHeader = "adb-authorization"
    4344
    func NewGRPCClient[T any](ctx context.Context, in func(cc grpc.ClientConnInterface) T, addr string, opts ...grpc.DialOption) (T, io.Closer, error) {
    4445
    con, err := NewGRPCConn(addr, opts...)
    4546
    if err != nil {
    46-
    return Default[T](), nil, err
    47+
    return util.Default[T](), nil, err
    4748
    }
    4849

    4950
    return in(con), con, nil
    @@ -52,7 +53,7 @@ func NewGRPCClient[T any](ctx context.Context, in func(cc grpc.ClientConnInterfa
    5253
    func NewOptionalTLSGRPCClient[T any](ctx context.Context, in func(cc grpc.ClientConnInterface) T, addr string, tls *tls.Config, opts ...grpc.DialOption) (T, io.Closer, error) {
    5354
    con, err := NewOptionalTLSGRPCConn(ctx, addr, tls, opts...)
    5455
    if err != nil {
    55-
    return Default[T](), nil, err
    56+
    return util.Default[T](), nil, err
    5657
    }
    5758

    5859
    return in(con), con, nil

    0 commit comments

    Comments
     (0)
    0