diff --git a/go.mod b/go.mod index 4cc5102f..87bc5ad4 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,6 @@ module github.com/redhat-partner-solutions/vse-sync-collection-tools go 1.18 require ( - github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 - github.com/icza/backscanner v0.0.0-20230330133933-bf6beb754c70 github.com/onsi/ginkgo/v2 v2.9.0 github.com/onsi/gomega v1.27.1 github.com/openshift/client-go v0.0.0-20230120202327-72f107311084 @@ -18,7 +16,6 @@ require ( ) require ( - github.com/creack/pty v1.1.17 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect diff --git a/go.sum b/go.sum index 61f7a366..b1437296 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= -github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= @@ -18,8 +16,6 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= -github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -86,10 +82,6 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/icza/backscanner v0.0.0-20230330133933-bf6beb754c70 h1:xrd41BUTgqxyYFfFwGdt/bnwS8KNYzPraj8WgvJ5NWk= -github.com/icza/backscanner v0.0.0-20230330133933-bf6beb754c70/go.mod h1:GYeBD1CF7AqnKZK+UCytLcY3G+UKo0ByXX/3xfdNyqQ= -github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k= -github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= @@ -152,7 +144,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= diff --git a/pkg/clients/exec_command.go b/pkg/clients/exec_command.go index 34ba9c46..e7d0d495 100644 --- a/pkg/clients/exec_command.go +++ b/pkg/clients/exec_command.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "os" "strings" "time" @@ -20,8 +21,8 @@ import ( ) const ( - startTimeout = 5 * time.Second - deletionTimeout = 10 * time.Minute + startTimeoutDefault = 5 * time.Second + deletionTimeoutDefault = 10 * time.Minute ) type ExecContext interface { @@ -175,6 +176,8 @@ type ContainerCreationExecContext struct { command []string volumes []*Volume hostNetwork bool + startTimeout time.Duration + deletionTimeout time.Duration } type Volume struct { @@ -271,7 +274,7 @@ func (c *ContainerCreationExecContext) isPodRunning() (bool, error) { func (c *ContainerCreationExecContext) waitForPodToStart() error { start := time.Now() - for time.Since(start) <= startTimeout { + for time.Since(start) <= c.startTimeout { running, err := c.isPodRunning() if err != nil { return err @@ -318,7 +321,7 @@ func (c *ContainerCreationExecContext) deletePod() error { func (c *ContainerCreationExecContext) waitForPodToDelete() error { start := time.Now() - for time.Since(start) <= deletionTimeout { + for time.Since(start) <= c.deletionTimeout { pods, err := c.listPods(&metav1.ListOptions{}) if err != nil { return err @@ -345,6 +348,18 @@ func (c *ContainerCreationExecContext) DeletePodAndWait() error { return c.waitForPodToDelete() } +func fetchDurationEnv(key string, defaultValue time.Duration) (time.Duration, error) { + timeoutStr, ok := os.LookupEnv(key) + if ok { + timeout, err := time.ParseDuration(timeoutStr) + if err != nil { + return defaultValue, fmt.Errorf("failed to parse %s as a duration: %w", key, err) + } + return timeout, nil + } + return defaultValue, nil +} + func NewContainerCreationExecContext( clientset *Clientset, namespace, podName, containerName, containerImage string, @@ -353,7 +368,7 @@ func NewContainerCreationExecContext( containerSecurityContext *corev1.SecurityContext, hostNetwork bool, volumes []*Volume, -) *ContainerCreationExecContext { +) (*ContainerCreationExecContext, error) { ctx := ContainerExecContext{ namespace: namespace, podNamePrefix: podName, @@ -362,7 +377,17 @@ func NewContainerCreationExecContext( clientset: clientset, } - return &ContainerCreationExecContext{ + startTimeout, err := fetchDurationEnv("COLLECTOR_POD_START_TIMEOUT", startTimeoutDefault) + if err != nil { + return nil, err + } + + deletionTimeout, err := fetchDurationEnv("COLLECTOR_POD_DELETE_TIMEOUT", deletionTimeoutDefault) + if err != nil { + return nil, err + } + + containerCTX := ContainerCreationExecContext{ ContainerExecContext: &ctx, containerImage: containerImage, labels: labels, @@ -370,5 +395,8 @@ func NewContainerCreationExecContext( containerSecurityContext: containerSecurityContext, hostNetwork: hostNetwork, volumes: volumes, + startTimeout: startTimeout, + deletionTimeout: deletionTimeout, } + return &containerCTX, nil } diff --git a/pkg/collectors/contexts/contexts.go b/pkg/collectors/contexts/contexts.go index 8bda10ea..3f22fcc3 100644 --- a/pkg/collectors/contexts/contexts.go +++ b/pkg/collectors/contexts/contexts.go @@ -30,7 +30,7 @@ func GetPTPDaemonContext(clientset *clients.Clientset) (clients.ExecContext, err func GetNetlinkContext(clientset *clients.Clientset) (*clients.ContainerCreationExecContext, error) { hpt := corev1.HostPathDirectory - ctx := clients.NewContainerCreationExecContext( + ctx, err := clients.NewContainerCreationExecContext( clientset, PTPNamespace, NetlinkDebugPod, @@ -59,5 +59,8 @@ func GetNetlinkContext(clientset *clients.Clientset) (*clients.ContainerCreation }, }, ) + if err != nil { + return ctx, fmt.Errorf("failed to create netlink context: %w", err) + } return ctx, nil }