Skip to content

Commit

Permalink
self service init - install rpm/deb and release complete image (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
bivas authored Aug 14, 2018
1 parent 3d64176 commit 191b9d1
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.deb
*.rpm
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ go_import_path: github.com/v3io/k8svol
go: "1.10"

script:
- docker build --tag iguaziodocker/flex-fuse:unstable .
- make build

2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RUN go build -o ${GOPATH}/fuse ${PROJECT_PATH}/cmd/fuse/main.go
FROM alpine:3.6

COPY hack/scripts/deploy.sh /usr/local/bin
COPY hack/scripts/install.sh /install.sh
COPY hack/libs /libs
COPY --from=builder /go/fuse /fuse

CMD ["/bin/ash","/usr/local/bin/deploy.sh"]
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
RPM_PATH = "iguazio_yum"
DEB_PATH = "iguazio_deb"
BINARY_NAME = "igz-fuse"

.PHONY: build
build:
docker build --tag iguaziodocker/flex-fuse:unstable .

.PHONY: download
download:
@rm -rf hack/libs/${BINARY_NAME}*
@cd hack/libs && wget --quiet $(MIRROR)/$(RPM_PATH)/$(IGUAZIO_VERSION)/$(BINARY_NAME).rpm
@cd hack/libs && wget --quiet $(MIRROR)/$(DEB_PATH)/$(IGUAZIO_VERSION)/$(BINARY_NAME).deb

.PHONY: release
release: check-req download build
docker tag iguaziodocker/flex-fuse:unstable iguaziodocker/flex-fuse:$(IGUAZIO_VERSION)-$(RELEASE_VERSION)

check-req:
ifndef MIRROR
$(error MIRROR must be set)
endif
ifndef IGUAZIO_VERSION
$(error IGUAZIO_VERSION must be set)
endif
ifndef RELEASE_VERSION
$(error RELEASE_VERSION must be set)
endif
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ the same volume (data container) can be accessed **simultaneously** by multiple

## Installation

Requierments:
- install v3io-fuse

When Kubernetes loads the plugin, v3io driver will install the required packages and v3io-fuse executable.
The following commands will be executed (check [install.sh](hack/scripts/install.sh) for complete overview):
```bash
$ yum install fuse librdmacm
$ rpm -iv v3io-fuse.rpm
$ rpm -ivh igz-fuse.rpm
```

## Security and Session Authentication
Expand Down
2 changes: 1 addition & 1 deletion cmd/fuse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func main() {
}

journal.Info("Completed flex flow", "result", result)
result.PrintJson()
result.ToJson()
}
Empty file added hack/libs/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions hack/scripts/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ cp "/$DRIVER" "/flexmnt/$driver_dir/.$DRIVER"
mv -f "/flexmnt/$driver_dir/.$DRIVER" "/flexmnt/$driver_dir/$DRIVER"

cp "/etc/config/v3io/v3io.conf" "/etc/v3io/fuse/v3io.conf"
cp "/install.sh" "/flexmnt/$driver_dir/"
cp -r "/libs" "/flexmnt/$driver_dir/"

while : ; do
sleep 3600
Expand Down
43 changes: 43 additions & 0 deletions hack/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -e

LIBS_DIR="$(dirname "$0")/libs"
PKG_MANAGER=""
PACKAGES="fuse librdmacm"
PACKAGE_NAME="igz-fuse"

echo "$(date) - checking yum or apt" >> /tmp/init.log
HAS_YUM=$(which yum &> /dev/null; echo $?)
HAS_APT=$(which apt &> /dev/null; echo $?)

if [ "${HAS_YUM}" == "0" ]; then
PKG_MANAGER="yum"
elif [ "${HAS_APT}" == "0" ]; then
PKG_MANAGER="apt-get"
PACKAGES="fuse librdmacm1"
apt-get update
else
echo "Installation supports 'yum' or 'apt-get'"
exit 1
fi

echo "$(date) - PKG_MANAGER is ${PKG_MANAGER}" >> /tmp/init.log

echo "Installing required packages"
echo "$(date) - Installing required packages - ${PACKAGES}" >> /tmp/init.log

${PKG_MANAGER} install -y ${PACKAGES} &>> /tmp/init.log

echo "Installing v3io-fuse package"
echo "$(date) - Installing v3io-fuse package" >> /tmp/init.log

if [ "${HAS_YUM}" == "0" ]; then
echo "$(date) - Installing v3io-fuse package using 'rpm -ivh ${LIBS_DIR}/${PACKAGE_NAME}.rpm'" >> /tmp/init.log
rpm -ivh ${LIBS_DIR}/${PACKAGE_NAME}.rpm &>> /tmp/init.log
else
echo "$(date) - Installing v3io-fuse package using 'dpkg -i ${LIBS_DIR}/${PACKAGE_NAME}.deb'" >> /tmp/init.log
dpkg -i ${LIBS_DIR}/${PACKAGE_NAME}.deb &>> /tmp/init.log
fi

echo "$(date) - Installation Completed" >> /tmp/init.log
35 changes: 26 additions & 9 deletions pkg/flex/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import (
"time"
)

/// Return status
func Init() *Response {
resp := MakeResponse("Success", "No Initialization required")
resp.Capabilities = map[string]interface{}{
"attach": false,
}
return resp
}

type Mounter struct {
Target string
Spec *VolumeSpec
Expand Down Expand Up @@ -166,3 +157,29 @@ func Unmount(target string) *Response {
return mounter.Unmount()
}
}

func Init() *Response {
journal.Info("calling init command")
config, err := ReadConfig()
if err != nil {
return Fail("Initialization script failed to read config", err)
}
_, staterr := os.Stat(config.FusePath)
if staterr != nil {
if os.IsNotExist(err) {
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)
}
}
return Fail("Initialization script failed to get fuse status", staterr)
}

resp := Success("Initialization completed")
resp.Capabilities = map[string]interface{}{
"attach": false,
}
return resp
}
14 changes: 11 additions & 3 deletions pkg/flex/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,20 @@ type Response struct {
Capabilities map[string]interface{} `json:"capabilities"`
}

func (r *Response) PrintJson() {
func (r *Response) String() string {
if len(r.Capabilities) > 0 {
return fmt.Sprintf("Response[Status=%s, Message=%s, Capabilities=%s]", r.Status, r.Message, r.Capabilities)
}
return fmt.Sprintf("Response[Status=%s, Message=%s]", r.Status, r.Message)
}

func (r *Response) ToJson() {
jsonBytes, err := json.Marshal(r)
if err != nil {
panic(err)
fmt.Printf(`{"status": "Failure", "Message": "%s"}`, err)
} else {
fmt.Printf("%s", string(jsonBytes))
}
fmt.Printf("%s", string(jsonBytes))
}

type VolumeSpec struct {
Expand Down

0 comments on commit 191b9d1

Please sign in to comment.