diff --git a/cmd/daemon/main.go b/cmd/daemon/main.go index 868ce67..75a1edb 100644 --- a/cmd/daemon/main.go +++ b/cmd/daemon/main.go @@ -6,20 +6,17 @@ import ( "net/http" "os" - "github.com/julz/freeze-proxy/pkg/daemon" authv1 "k8s.io/api/authentication/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - "github.com/julz/freeze-proxy/pkg/freezer" + "github.com/julz/freeze-proxy/pkg/daemon" + "github.com/julz/freeze-proxy/pkg/freeze" ) -var runtimeType string - -func init() { - runtimeType = os.Getenv("RUNTIME_TYPE") -} func main() { + runtimeType := os.Getenv("RUNTIME_TYPE") + config, err := rest.InClusterConfig() if err != nil { log.Fatal(err) @@ -30,18 +27,18 @@ func main() { log.Fatal(err) } - fre, err := freezer.GetFreezer(runtimeType) + freezer, err := freeze.GetFreezer(runtimeType) if err != nil { log.Fatal(err) } - thawer, err := freezer.GetThawer(runtimeType) + thawer, err := freeze.GetThawer(runtimeType) if err != nil { log.Fatal(err) } http.ListenAndServe(":8080", &daemon.Handler{ - Freezer: fre, + Freezer: freezer, Thawer: thawer, Validator: daemon.TokenValidatorFunc(func(ctx context.Context, token string) (*authv1.TokenReview, error) { return clientset.AuthenticationV1().TokenReviews().CreateContext(ctx, &authv1.TokenReview{ diff --git a/pkg/freezer/containerd/pause.go b/pkg/freeze/containerd/pause.go similarity index 100% rename from pkg/freezer/containerd/pause.go rename to pkg/freeze/containerd/pause.go diff --git a/pkg/freezer/docker/pause.go b/pkg/freeze/docker/pause.go similarity index 89% rename from pkg/freezer/docker/pause.go rename to pkg/freeze/docker/pause.go index 077da92..cb336ff 100644 --- a/pkg/freezer/docker/pause.go +++ b/pkg/freeze/docker/pause.go @@ -10,22 +10,20 @@ import ( dockerapi "github.com/docker/docker/client" ) -const DefaultDockerUri = "unix:///var/run/docker.sock" -const Version = "1.19" +const defaultDockerUri = "unix:///var/run/docker.sock" +const version = "1.19" type Docker struct { client *dockerapi.Client } func NewDockerService() (*Docker, error) { - r := &Docker{} - c, err := dockerapi.NewClientWithOpts(dockerapi.WithHost(DefaultDockerUri), - dockerapi.WithVersion(Version)) + c, err := dockerapi.NewClientWithOpts(dockerapi.WithHost(defaultDockerUri), + dockerapi.WithVersion(version)) if err != nil { return nil, err } - r.client = c - return r, nil + return &Docker{client: c}, nil } func (d *Docker) Freeze(ctx context.Context, podUID, containerName string) error { diff --git a/pkg/freezer/factory.go b/pkg/freeze/freeze.go similarity index 85% rename from pkg/freezer/factory.go rename to pkg/freeze/freeze.go index 892a6d3..2f91424 100644 --- a/pkg/freezer/factory.go +++ b/pkg/freeze/freeze.go @@ -1,11 +1,11 @@ -package freezer +package freeze import ( "fmt" "github.com/julz/freeze-proxy/pkg/daemon" - "github.com/julz/freeze-proxy/pkg/freezer/containerd" - docker "github.com/julz/freeze-proxy/pkg/freezer/docker" + "github.com/julz/freeze-proxy/pkg/freeze/containerd" + docker "github.com/julz/freeze-proxy/pkg/freeze/docker" ) const (