Skip to content

Commit

Permalink
Remove session flow (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
bivas authored Nov 20, 2018
1 parent 82b50a9 commit 939adca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RPM_PATH = "iguazio_yum"
DEB_PATH = "iguazio_deb"
BINARY_NAME = "igz-fuse"
RELEASE_VERSION = "0.5.2"
RELEASE_VERSION = "0.6.0"
DOCKER_HUB_USER = "iguaziodocker"

.PHONY: build
Expand Down
5 changes: 2 additions & 3 deletions hack/kubernetes/v3fs-ds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ data:
"clusters": [
{
"name": "default",
"data_url": "tcp://172.31.32.50:1234",
"api_url": "http://172.31.32.50:8001"
"data_urls": ["tcp://172.31.32.50:1234"]
}
]
}
Expand All @@ -67,4 +66,4 @@ type: v3io/fuse
data:
username: aWd1YXppbw==
#tenant: aWd1YXppbw==
password: YThhNHl6dlBMb2g2UU5JcQ==
accessKey: YThhNHl6dlBMb2g2UU5JcQ==
20 changes: 13 additions & 7 deletions pkg/flex/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flex

import (
"encoding/json"
"errors"
"fmt"
"github.com/v3io/k8svol/pkg/journal"
"os"
Expand All @@ -18,11 +19,6 @@ type Mounter struct {
}

func (m *Mounter) doMount(targetPath string) *Response {
session, err := m.Config.DataSession(m.Spec)
if err != nil {
return Fail("Could not create session", err)
}

dataUrls, err := m.Config.DataURLs(m.Spec.GetClusterName())
if err != nil {
return Fail("could not get cluster data urls", err)
Expand All @@ -31,7 +27,7 @@ func (m *Mounter) doMount(targetPath string) *Response {
args := []string{"-o", "allow_other",
"--connection_strings", dataUrls,
"--mountpoint", targetPath,
"--session_key", session}
"--session_key", m.Spec.GetAccessKey()}
if m.Spec.Container != "" {
args = append(args, "-a", m.Spec.Container)
}
Expand Down Expand Up @@ -67,6 +63,9 @@ func (m *Mounter) osMount() *Response {
}

func (m *Mounter) Mount() *Response {
if err := m.validate(); err != nil {
return Fail("Mount failed validation", err)
}
if m.Config.Type == "link" {
return m.mountAsLink()
}
Expand Down Expand Up @@ -126,6 +125,13 @@ func (m *Mounter) Unmount() *Response {
return m.osUmount()
}

func (m *Mounter) validate() error {
if m.Spec.Username == "" || m.Spec.AccessKey == "" {
errors.New("missing username or access key")
}
return nil
}

func NewMounter(target, options string) (*Mounter, error) {
opts := VolumeSpec{}
if options != "" {
Expand Down Expand Up @@ -174,7 +180,7 @@ func Init() *Response {

location := path.Dir(os.Args[0])
command := exec.Command("/bin/bash", path.Join(location, "install.sh"))

journal.Debug("Calling install command", "path", command.Path, "args", command.Args)
if err := command.Run(); err != nil {
return Fail("Initialization script failed", err)
Expand Down
65 changes: 6 additions & 59 deletions pkg/flex/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,11 @@ import (
"fmt"
"github.com/v3io/k8svol/pkg/journal"
"io/ioutil"
"net/http"
"strings"
)

const (
v3ioConfig = "/etc/v3io/fuse/v3io.conf"
v3ioSessionPayloadTemplate = `{
"data": {
"type": "session",
"attributes": {
"plane": "%s",
"interface_kind": "fuse",
"username": "%s",
"password": "%s"
}
}
}`
v3ioConfig = "/etc/v3io/fuse/v3io.conf"
)

func ReadConfig() (*Config, error) {
Expand All @@ -42,7 +30,6 @@ func ReadConfig() (*Config, error) {
type ClusterConfig struct {
Name string `json:"name"`
DataUrls []string `json:"data_urls"`
ApiUrl string `json:"api_url"`
}

type Config struct {
Expand All @@ -53,12 +40,6 @@ type Config struct {
Clusters []ClusterConfig `json:"clusters"`
}

type sessionResponse struct {
Data struct {
Id string `json:"id"`
} `json:"data"`
}

func (c *Config) findCluster(cluster string) (*ClusterConfig, error) {
for _, clusterConfig := range c.Clusters {
if clusterConfig.Name == cluster {
Expand All @@ -80,45 +61,6 @@ func (c *Config) DataURLs(cluster string) (string, error) {
return strings.Join(result, ","), nil
}

func (c *Config) ControlSession(spec *VolumeSpec) (string, error) {
return c.Session(spec.GetClusterName(), spec.GetFullUsername(), spec.GetPassword(), "control")
}

func (c *Config) DataSession(spec *VolumeSpec) (string, error) {
return c.Session(spec.GetClusterName(), spec.GetFullUsername(), spec.GetPassword(), "data")
}

func (c *Config) Session(cluster, username, password, plane string) (string, error) {
clusterConfig, err := c.findCluster(cluster)
if err != nil {
return "", err
}
payload := strings.NewReader(fmt.Sprintf(v3ioSessionPayloadTemplate, plane, username, password))
journal.Debug("Creating session", "plane", plane, "url", fmt.Sprintf("%s/api/sessions", clusterConfig.ApiUrl))
response, err := http.Post(
fmt.Sprintf("%s/api/sessions", clusterConfig.ApiUrl),
"application/json",
payload)
if err != nil {
return "", err
}
defer response.Body.Close()
bodyBytes, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
journal.Debug("Result from creating session", "status", response.Status, "body", string(bodyBytes))
if response.StatusCode != 201 {
return "", fmt.Errorf("error creating session. %d : %s", response.StatusCode, response.Status)
}
responseM := sessionResponse{}
if err := json.Unmarshal(bodyBytes, &responseM); err != nil {
return "", err
}
journal.Info("Created session id", responseM.Data.Id)
return responseM.Data.Id, nil
}

type Response struct {
Status string `json:"status"`
Message string `json:"message"`
Expand Down Expand Up @@ -147,6 +89,7 @@ type VolumeSpec struct {
Cluster string `json:"cluster"`
Username string `json:"kubernetes.io/secret/username"`
Password string `json:"kubernetes.io/secret/password"`
AccessKey string `json:"kubernetes.io/secret/accessKey"`
Tenant string `json:"kubernetes.io/secret/tenant"`
PodName string `json:"kubernetes.io/pod.name"`
Namespace string `json:"kubernetes.io/pod.namespace"`
Expand All @@ -173,6 +116,10 @@ func (vs *VolumeSpec) GetPassword() string {
return vs.decodeOrDefault(vs.Password)
}

func (vs *VolumeSpec) GetAccessKey() string {
return vs.decodeOrDefault(vs.AccessKey)
}

func (vs *VolumeSpec) GetFullUsername() string {
if vs.Tenant != "" {
return fmt.Sprintf("%s@%s", vs.GetUsername(), vs.GetTenant())
Expand Down

0 comments on commit 939adca

Please sign in to comment.