Skip to content

Commit

Permalink
Revert GORM changes (#3554)
Browse files Browse the repository at this point in the history
Co-authored-by: luhi-DT <[email protected]>
Co-authored-by: Lukas Hinterreiter <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2024
1 parent 8763cca commit 271f583
Show file tree
Hide file tree
Showing 44 changed files with 2,913 additions and 3,075 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ linters-settings:
- "github.com/docker/cli"
- "github.com/go-gormigrate/gormigrate"
- "github.com/google/uuid"
- "github.com/google/go-cmp/cmp"

# Allowed packages in container-based builder.
deny:
Expand Down
6 changes: 0 additions & 6 deletions cmd/csi/init/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,10 @@ func (builder CommandBuilder) buildRun() func(*cobra.Command, []string) error {

signalHandler := ctrl.SetupSignalHandler()

// new schema
access, err := metadata.NewAccess(signalHandler, dtcsi.MetadataAccessPath)
if err != nil {
return err
}
// new migrations
err = access.SchemaMigration()
if err != nil {
return err
}

csiOptions := dtcsi.CSIOptions{
NodeId: nodeId,
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/google/go-containerregistry v0.19.2
github.com/google/uuid v1.6.0
github.com/klauspost/compress v1.17.9
github.com/mattn/go-sqlite3 v1.14.22
github.com/opencontainers/go-digest v1.0.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
Expand Down Expand Up @@ -88,9 +89,9 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down Expand Up @@ -125,6 +126,7 @@ require (
k8s.io/component-base v0.30.3 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/mount-utils v0.30.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78=
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -251,6 +253,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -321,6 +324,8 @@ k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
k8s.io/mount-utils v0.30.3 h1:8Z3wSW5+GSvGNtlDhtoZrBCKLMIf5z/9tf8pie+G06s=
k8s.io/mount-utils v0.30.3/go.mod h1:9sCVmwGLcV1MPvbZ+rToMDnl1QcGozy+jBPd0MsQLIo=
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak=
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw=
Expand Down
5 changes: 0 additions & 5 deletions pkg/controllers/csi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package dtcsi

import (
"path/filepath"
"time"
)

const (
Expand All @@ -36,10 +35,6 @@ const (
DaemonSetName = "dynatrace-oneagent-csi-driver"

UnixUmask = 0000

ShortRequeueDuration = 1 * time.Minute
DefaultRequeueDuration = 5 * time.Minute
LongRequeueDuration = 30 * time.Minute
)

var MetadataAccessPath = filepath.Join(DataPath, "csi.db")
Expand Down
29 changes: 9 additions & 20 deletions pkg/controllers/csi/driver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/utils/mount"
mount "k8s.io/mount-utils"
ctrl "sigs.k8s.io/controller-runtime"
)

Expand Down Expand Up @@ -145,7 +145,7 @@ func (svr *Server) NodePublishVolume(ctx context.Context, req *csi.NodePublishVo
return nil, err
}

if isMounted, err := isMounted(svr.mounter, volumeCfg.TargetPath); err != nil {
if isMounted, err := svr.mounter.IsMountPoint(volumeCfg.TargetPath); err != nil && !os.IsNotExist(err) {
return nil, err
} else if isMounted {
return &csi.NodePublishVolumeResponse{}, nil
Expand All @@ -166,25 +166,25 @@ func (svr *Server) NodePublishVolume(ctx context.Context, req *csi.NodePublishVo
"mountflags", req.GetVolumeCapability().GetMount().GetMountFlags(),
)

return publisher.PublishVolume(ctx, *volumeCfg)
return publisher.PublishVolume(ctx, volumeCfg)
}

func (svr *Server) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (response *csi.NodeUnpublishVolumeResponse, err error) {
func (svr *Server) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
volumeInfo, err := csivolumes.ParseNodeUnpublishVolumeRequest(req)
if err != nil {
return nil, err
}

for _, publisher := range svr.publishers {
canUnpublish, err := publisher.CanUnpublishVolume(ctx, *volumeInfo)
canUnpublish, err := publisher.CanUnpublishVolume(ctx, volumeInfo)
if err != nil {
log.Error(err, "couldn't determine if volume can be unpublished", "publisher", publisher)
}

if canUnpublish {
response, err := publisher.UnpublishVolume(ctx, *volumeInfo)
response, err := publisher.UnpublishVolume(ctx, volumeInfo)
if err != nil {
log.Error(err, "couldn't unpublish volume properly", "publisher", publisher)
return nil, err
}

return response, nil
Expand All @@ -197,10 +197,10 @@ func (svr *Server) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpubli
}

func (svr *Server) unmountUnknownVolume(volumeInfo csivolumes.VolumeInfo) {
log.Info("unmounting unknown volume", "volumeID", volumeInfo.VolumeID, "targetPath", volumeInfo.TargetPath)
log.Info("VolumeID not present in the database", "volumeID", volumeInfo.VolumeID, "targetPath", volumeInfo.TargetPath)

if err := svr.mounter.Unmount(volumeInfo.TargetPath); err != nil {
log.Error(err, "failed to unmount unknown volume", "volumeID", volumeInfo.VolumeID)
log.Error(err, "Tried to unmount unknown volume", "volumeID", volumeInfo.VolumeID)
}
}

Expand Down Expand Up @@ -228,17 +228,6 @@ func (svr *Server) NodeExpandVolume(context.Context, *csi.NodeExpandVolumeReques
return nil, status.Error(codes.Unimplemented, "")
}

func isMounted(mounter mount.Interface, targetPath string) (bool, error) {
isNotMounted, err := mount.IsNotMountPoint(mounter, targetPath)
if os.IsNotExist(err) {
isNotMounted = true
} else if err != nil {
return false, status.Error(codes.Internal, err.Error())
}

return !isNotMounted, nil
}

func logGRPC() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
if info.FullMethod == "/csi.v1.Identity/Probe" || info.FullMethod == "/csi.v1.Node/NodeGetCapabilities" {
Expand Down
55 changes: 0 additions & 55 deletions pkg/controllers/csi/driver/server_test.go
Original file line number Diff line number Diff line change
@@ -1,67 +1,12 @@
package csidriver

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/utils/mount"
)

const (
testTargetNotExist = "not-exists"
testTargetError = "error"
testTargetNotMounted = "not-mounted"
testTargetMounted = "mounted"

testError = "test error message"
)

type fakeMounter struct {
mount.FakeMounter
}

func (*fakeMounter) IsLikelyNotMountPoint(target string) (bool, error) {
switch {
case target == testTargetNotExist:
return false, os.ErrNotExist
case target == testTargetError:
return false, fmt.Errorf(testError)
case target == testTargetMounted:
return true, nil
}

return false, nil
}

func TestCSIDriverServer_IsMounted(t *testing.T) {
t.Run(`mount point does not exist`, func(t *testing.T) {
mounted, err := isMounted(&fakeMounter{}, testTargetNotExist)
require.NoError(t, err)
assert.False(t, mounted)
})
t.Run(`mounter throws error`, func(t *testing.T) {
mounted, err := isMounted(&fakeMounter{}, testTargetError)

require.EqualError(t, err, "rpc error: code = Internal desc = test error message")
assert.False(t, mounted)
})
t.Run(`mount point is not mounted`, func(t *testing.T) {
mounted, err := isMounted(&fakeMounter{}, testTargetNotMounted)

require.NoError(t, err)
assert.True(t, mounted)
})
t.Run(`mount point is mounted`, func(t *testing.T) {
mounted, err := isMounted(&fakeMounter{}, testTargetMounted)

require.NoError(t, err)
assert.False(t, mounted)
})
}

func TestCSIDriverServer_parseEndpoint(t *testing.T) {
t.Run(`valid unix endpoint`, func(t *testing.T) {
testEndpoint := "unix:///some/socket"
Expand Down
Loading

0 comments on commit 271f583

Please sign in to comment.