Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from kumarabd/kumarabd/feature/init
Browse files Browse the repository at this point in the history
minor bug fix on service type
  • Loading branch information
leecalcote authored Aug 20, 2020
2 parents 469e321 + 0876939 commit 6c887dc
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 30 deletions.
37 changes: 35 additions & 2 deletions osm/install.go → osm/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ var (
)

// installMesh installs the mesh
func (iClient *Client) installMesh(method string, version string) error {
func (iClient *Client) installMesh(method string, version string, deleteOp bool) error {

if deleteOp {
return deleteOSM(version)
}

if _, ok := releases[version]; !ok {
return errors.New(fmt.Sprintf("version %s unavailable", version))
Expand All @@ -35,7 +39,36 @@ func (iClient *Client) installMesh(method string, version string) error {

// applyOSM applies mesh resources with osmctl
func applyOSM(version string) error {
Executable, err := exec.LookPath("./scripts/osmctl.sh")
Executable, err := exec.LookPath("./scripts/create_osmctl.sh")
if err != nil {
return err
}

cmd := &exec.Cmd{
Path: Executable,
Args: []string{Executable},
Stdout: os.Stdout,
Stderr: os.Stdout,
}
cmd.Env = append(os.Environ(),
fmt.Sprintf("OSM_VERSION=%s", version),
)

err = cmd.Start()
if err != nil {
return err
}
err = cmd.Wait()
if err != nil {
return err
}

return nil
}

// deleteOSM deletes mesh resources with osmctl
func deleteOSM(version string) error {
Executable, err := exec.LookPath("./scripts/delete_osmctl.sh")
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions osm/osm.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (iClient *Client) ApplyOperation(_ context.Context, arReq *meshes.ApplyRule
if arReq.DeleteOp {
opName = "removing"
}
if err := iClient.installMesh("osmctl", "v0.3.0"); err != nil {
if err := iClient.installMesh("osmctl", "v0.3.0", arReq.DeleteOp); err != nil {
iClient.eventChan <- &meshes.EventsResponse{
OperationId: arReq.OperationId,
EventType: meshes.EventType_ERROR,
Expand Down Expand Up @@ -121,7 +121,7 @@ func (iClient *Client) ApplyOperation(_ context.Context, arReq *meshes.ApplyRule
return
}

err = iClient.startConformanceTool(context.TODO())
err = iClient.connectConformanceTool(context.TODO())
if err != nil {
iClient.eventChan <- &meshes.EventsResponse{
OperationId: arReq.OperationId,
Expand Down
51 changes: 33 additions & 18 deletions osm/smi_conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"os"
"os/exec"
"time"
Expand Down Expand Up @@ -106,21 +107,46 @@ func (iClient *Client) deleteConformanceTool(req *meshes.ApplyRuleRequest) error
return nil
}

// startConformanceTool initiates the connection
func (iClient *Client) startConformanceTool(ctx context.Context) error {
// connectConformanceTool initiates the connection
func (iClient *Client) connectConformanceTool(ctx context.Context) error {
var host string
var port int32

svc, err := iClient.k8sClientset.CoreV1().Services("meshery").Get(ctx, "smi-conformance", metav1.GetOptions{})
if err != nil {
return errors.New("Unable to get service: " + err.Error())
}

host := svc.Status.LoadBalancer.Ingress[0].IP
if host == "127.0.0.1" {
host = "minikubeCA"
nodes, err := iClient.k8sClientset.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
if err != nil {
return errors.New("Unable to get nodes: " + err.Error())
}
addresses := make(map[string]string, 0)
for _, addr := range nodes.Items[0].Status.Addresses {
addresses[string(addr.Type)] = addr.Address
}
iClient.smiAddress = fmt.Sprintf("%s:%d", host, svc.Spec.Ports[0].Port)
host = addresses["ExternalIP"]
port = svc.Spec.Ports[0].NodePort
if tcpCheck(addresses["InternalIP"], port) {
host = addresses["InternalIP"]
}

iClient.smiAddress = fmt.Sprintf("%s:%d", host, port)
return nil
}

func tcpCheck(ip string, port int32) bool {
timeout := 5 * time.Second
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), timeout)
if err != nil {
return false
}
if conn != nil {
return true
}
return false
}

// runConformanceTest runs the conformance test
func (iClient *Client) runConformanceTest(adaptorname string, arReq *meshes.ApplyRuleRequest) error {
annotations := make(map[string]string, 0)
Expand All @@ -136,14 +162,9 @@ func (iClient *Client) runConformanceTest(adaptorname string, arReq *meshes.Appl
cClient, err := conformance.CreateClient(context.TODO(), iClient.smiAddress)
if err != nil {
logrus.Error(err)
iClient.eventChan <- &meshes.EventsResponse{
OperationId: arReq.OperationId,
EventType: meshes.EventType_ERROR,
Summary: "Error creating a smi conformance tool client.",
Details: err.Error(),
}
return err
}
defer cClient.Close()
logrus.Debugf("created client for smi conformance tool: %s", adaptorname)

result, err := cClient.CClient.RunTest(context.TODO(), &conformance.Request{
Expand All @@ -153,12 +174,6 @@ func (iClient *Client) runConformanceTest(adaptorname string, arReq *meshes.Appl
})
if err != nil {
logrus.Error(err)
iClient.eventChan <- &meshes.EventsResponse{
OperationId: arReq.OperationId,
EventType: meshes.EventType_ERROR,
Summary: "Test failed",
Details: err.Error(),
}
return err
}
logrus.Debugf("Tests ran successfully for smi conformance tool!!")
Expand Down
4 changes: 0 additions & 4 deletions scripts/osmctl.sh → scripts/create_osmctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,4 @@ if ! ./$OS-$OSM_ARCH/osm install; then
fi
printf "INFO\tDeployment successfull!!\n"

if ! rm -rf $OS-$OSM_ARCH; then
printf "ERROR\tUnable to clear temperory files!"
fi

printf "INFO\tOpen service mesh has been installed successfully!!\n"
2 changes: 1 addition & 1 deletion scripts/create_smi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ if ! kubectl apply -f ./scripts/smi-conformance.yaml; then
printf "ERROR\tUnable to deploy\n"
exit 1
fi
printf "INFO\tSMI Deployment successfull!!\n"
printf "INFO\tSMI Deployment successfull\n"
28 changes: 28 additions & 0 deletions scripts/delete_osmctl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

set -e

: "${OSM_VERSION:=}"
: "${OSM_ARCH:=amd64}"
: "${OS:=$(uname | awk '{print tolower($0)}')}"
URL="https://github.com/openservicemesh/osm/releases/download/$OSM_VERSION/osm-$OSM_VERSION-$OS-$OSM_ARCH.tar.gz"

printf "INFO\tDownloading osmctl from: %s" "$URL"
printf "\n\n"

if curl -L "$URL" | tar xz; then
printf "\n"
printf "INFO\tosmctl %s has been downloaded!\n" "$OSM_VERSION"
printf "\n"
else
printf "\n"
printf "ERROR\tUnable to download osmctl\n"
exit 1
fi

printf "INFO\tDeleting deployment......\n"
if ! ./$OS-$OSM_ARCH/osm delete; then
printf "ERROR\tUnable to delete\n"
exit 1
fi
printf "INFO\tDeleted successfully\n"
7 changes: 4 additions & 3 deletions scripts/smi-conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ spec:
protocol: TCP
resources:
limits:
cpu: "1"
cpu: "500m"
memory: 1000Mi
requests:
cpu: "500m"
cpu: "200m"
memory: 500Mi
restartPolicy: Always
serviceAccount: meshery
Expand All @@ -63,10 +63,11 @@ metadata:
labels:
app: smi-conformance
spec:
type: LoadBalancer
type: NodePort
ports:
- name: smi-conformance
port: 10008
targetPort: 10008
protocol: TCP
selector:
app: smi-conformance
Expand Down

0 comments on commit 6c887dc

Please sign in to comment.