Skip to content

Commit

Permalink
Code changes for new packages
Browse files Browse the repository at this point in the history
  • Loading branch information
nwneisen committed Nov 30, 2023
1 parent 852781b commit 49cbf90
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/docker_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/clock"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
"k8s.io/utils/clock"

"github.com/Mirantis/cri-dockerd/libdocker"
"github.com/Mirantis/cri-dockerd/network"
Expand Down
2 changes: 1 addition & 1 deletion libdocker/fake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
dockerimagetypes "github.com/docker/docker/api/types/image"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
)

type CalledDetail struct {
Expand Down
10 changes: 6 additions & 4 deletions network/hostport/hostport_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
iptablesproxy "k8s.io/kubernetes/pkg/proxy/iptables"
"k8s.io/kubernetes/pkg/util/conntrack"
utiliptables "k8s.io/kubernetes/pkg/util/iptables"
"k8s.io/utils/exec"
Expand Down Expand Up @@ -156,7 +155,7 @@ func (hm *hostportManager) Add(
writeLine(natRules, "-A", string(chain),
"-m", "comment", "--comment", fmt.Sprintf(`"%s hostport %d"`, podFullName, pm.HostPort),
"-s", podIP,
"-j", string(iptablesproxy.KubeMarkMasqChain))
"-j", "KUBE-MARK-MASQ") // iptablesproxy "k8s.io/kubernetes/pkg/proxy/iptables" is too cool to stay imported

// DNAT to the podIP:containerPort
hostPortBinding := net.JoinHostPort(podIP, strconv.Itoa(int(pm.ContainerPort)))
Expand Down Expand Up @@ -424,15 +423,18 @@ func getExistingHostportIPTablesRules(
if err != nil { // if we failed to get any rules
return nil, nil, fmt.Errorf("failed to execute iptables-save: %v", err)
}
existingNATChains := utiliptables.GetChainLines(utiliptables.TableNAT, iptablesData.Bytes())
existingNATChains := utiliptables.GetChainsFromTable(iptablesData.Bytes())

existingHostportChains := make(map[utiliptables.Chain]string)
existingHostportRules := []string{}

for chain := range existingNATChains {
if strings.HasPrefix(string(chain), string(kubeHostportsChain)) ||
strings.HasPrefix(string(chain), kubeHostportChainPrefix) {
existingHostportChains[chain] = string(existingNATChains[chain])
if _, ok := existingNATChains[chain]; ok {
// This just means true
existingHostportChains[chain] = ""
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion streaming/request_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"sync"
"time"

"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion streaming/request_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/utils/clock"
)

func TestInsert(t *testing.T) {
Expand Down
19 changes: 10 additions & 9 deletions streaming/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package streaming

import (
"context"
"crypto/tls"
"errors"
"io"
Expand Down Expand Up @@ -61,9 +62,9 @@ type Server interface {

// Runtime is the interface to execute the commands and provide the streams.
type Runtime interface {
Exec(containerID string, cmd []string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error
Attach(containerID string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error
PortForward(podSandboxID string, port int32, stream io.ReadWriteCloser) error
Exec(ctx context.Context, containerID string, cmd []string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error
Attach(ctx context.Context, containerID string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error
PortForward(ctx context.Context, podSandboxID string, port int32, stream io.ReadWriteCloser) error
}

// Config defines the options used for running the stream server.
Expand Down Expand Up @@ -369,14 +370,14 @@ var _ remotecommandserver.Executor = &criAdapter{}
var _ remotecommandserver.Attacher = &criAdapter{}
var _ portforward.PortForwarder = &criAdapter{}

func (a *criAdapter) ExecInContainer(podName string, podUID types.UID, container string, cmd []string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize, timeout time.Duration) error {
return a.Runtime.Exec(container, cmd, in, out, err, tty, resize)
func (a *criAdapter) ExecInContainer(ctx context.Context, podname string, podUID types.UID, container string, cmd []string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize, timeout time.Duration) error {
return a.Runtime.Exec(ctx, container, cmd, in, out, err, tty, resize)
}

func (a *criAdapter) AttachContainer(podName string, podUID types.UID, container string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error {
return a.Runtime.Attach(container, in, out, err, tty, resize)
func (a *criAdapter) AttachContainer(ctx context.Context, podName string, podUID types.UID, container string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error {
return a.Runtime.Attach(ctx, container, in, out, err, tty, resize)
}

func (a *criAdapter) PortForward(podName string, podUID types.UID, port int32, stream io.ReadWriteCloser) error {
return a.Runtime.PortForward(podName, port, stream)
func (a *criAdapter) PortForward(ctx context.Context, podName string, podUID types.UID, port int32, stream io.ReadWriteCloser) error {
return a.Runtime.PortForward(ctx, podName, port, stream)
}
3 changes: 3 additions & 0 deletions streaming/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ExecHandler interface {
var _ streaming.Runtime = &StreamingRuntime{}

func (r *StreamingRuntime) Exec(
ctx context.Context,
containerID string,
cmd []string,
in io.Reader,
Expand Down Expand Up @@ -97,6 +98,7 @@ func (r *StreamingRuntime) ExecWithContext(
}

func (r *StreamingRuntime) Attach(
ctx context.Context,
containerID string,
in io.Reader,
out, errw io.WriteCloser,
Expand All @@ -112,6 +114,7 @@ func (r *StreamingRuntime) Attach(
}

func (r *StreamingRuntime) PortForward(
ctx context.Context,
podSandboxID string,
port int32,
stream io.ReadWriteCloser,
Expand Down

0 comments on commit 49cbf90

Please sign in to comment.