Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added saving command to annotation feature #733

Merged
merged 1 commit into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/transformer/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like how we have an exec command here... but I don't think there's an alternative way to do this getting the actual Git hash...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no option for that as of now

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
259 changes: 195 additions & 64 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