Skip to content

Commit

Permalink
Adding save command to annotation
Browse files Browse the repository at this point in the history
This command will add `kompose command` used to generate artifacts as well as `kompose version`,
for ex,

```
metadata:
    annotations:
      kompose.cmd: kompose convert -f /home/snarwade --stdout
      kompose.version: 1.0.0 (HEAD)
```

For functional test, Now each test has template like,

```
 "annotations": {
           "kompose.cmd": "%CMD%",
           "kompose.version": "%VERSION%"
```

Because, for every machine these values will be different.

Updated functional test with new annotations
  • Loading branch information
surajnarwade committed Aug 11, 2017
1 parent a9bffa6 commit ffe2c0e
Show file tree
Hide file tree
Showing 56 changed files with 1,760 additions and 84 deletions.
4 changes: 1 addition & 3 deletions pkg/transformer/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ func checkMeta(config kobject.ServiceConfig, meta api.ObjectMeta, expectedName s
if expectedName != meta.Name {
return fmt.Errorf("Found unexpected name: %s vs. %s", expectedName, meta.Name)
}
if !equalStringMaps(config.Annotations, meta.Annotations) {
return fmt.Errorf("Found different annotations: %#v vs. %#v", config.Annotations, meta.Annotations)
}

if shouldSetLabels != (len(meta.Labels) > 0) {
return fmt.Errorf("Unexpected labels: %#v", meta.Labels)
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/transformer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/kubernetes/kompose/pkg/kobject"

"github.com/kubernetes/kompose/pkg/utils/docker"
"path/filepath"

"github.com/kubernetes/kompose/pkg/utils/docker"

"github.com/pkg/errors"
"k8s.io/kubernetes/pkg/api"
)
Expand Down Expand Up @@ -114,7 +116,14 @@ func ConfigAnnotations(service kobject.ServiceConfig) map[string]string {
for key, value := range service.Annotations {
annotations[key] = value
}
annotations["kompose.cmd"] = strings.Join(os.Args, " ")
version := exec.Command("kompose", "version")
out, err := version.Output()
if err != nil {
errors.Wrap(err, "Failed to get kompose version")

}
annotations["kompose.version"] = strings.Trim(string(out), " \n")
return annotations
}

Expand Down
251 changes: 189 additions & 62 deletions script/test/cmd/tests.sh

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions script/test/fixtures/buildargs/output-os-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "foo"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -38,6 +42,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "foo1"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -65,6 +73,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "foo"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -155,6 +167,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "foo"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -205,6 +221,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "foo1"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -295,6 +315,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "foo1"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -38,6 +42,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "web"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand All @@ -64,6 +72,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -98,6 +110,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "web"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -38,6 +42,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "web"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand All @@ -64,6 +72,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -150,6 +162,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "web"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "base"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -38,6 +42,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "base"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "base"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down Expand Up @@ -38,6 +42,10 @@
"creationTimestamp": null,
"labels": {
"io.kompose.service": "base"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
Expand Down
Loading

0 comments on commit ffe2c0e

Please sign in to comment.