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

Add support for using goss to target Windows #39

Merged
merged 2 commits into from
Feb 25, 2021

Conversation

jsturtevant
Copy link
Contributor

This provisioner is used to provide goss testing in the image-builder project. I recently added Windows support to image-builder and would like to run the goss test against it during provision in the same manner as the other images. Goss also now has alpha support for Windows.

I've updated the code here to support Windows and added a few tests.

Here is the output of it running against a windows VM. It is using a custom goss url while I wait for the fix in goss goss-org/goss#666

==> vhd-windows-2019: Provisioning with Goss
==> vhd-windows-2019: Configured to run on Windows
    vhd-windows-2019: Creating directory: /tmp/goss
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019:     Directory: C:\tmp
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019: Mode                LastWriteTime         Length Name
    vhd-windows-2019: ----                -------------         ------ ----
    vhd-windows-2019: d-----       12/17/2020   6:37 PM                goss
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019: Installing Goss from, https://k8swin.blob.core.windows.net/k8s-windows/goss/goss-alpha-windows-amd64.exe
    vhd-windows-2019: Downloading Goss to /tmp/goss-windows-amd64.exe
==> vhd-windows-2019:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
==> vhd-windows-2019:                                  Dload  Upload   Total   Spent    Left  Speed
==> vhd-windows-2019: 100 11.5M  100 11.5M    0     0  11.5M      0  0:00:01 --:--:--  0:00:01 26.4M
==> vhd-windows-2019: 'chmod' is not recognized as an internal or external command,
==> vhd-windows-2019: operable program or batch file.
==> vhd-windows-2019: Uploading goss tests...
    vhd-windows-2019: Uploading vars file packer/goss/goss-vars.yaml
    vhd-windows-2019: Inline variables are --vars-inline {"ARCH":"amd64","OS":"windows","PROVIDER":"azure","containerd_version":"1.4.3","kubernetes_cni_source_type":"","kubernetes_cni_version":"","kubernetes_source_type":"pkg","kubernetes_version":"v1.17.11"}
    vhd-windows-2019: Env variables are set "GOSS_USE_ALPHA=1" &&
    vhd-windows-2019: Uploading Dir packer/goss
    vhd-windows-2019: Creating directory: /tmp/goss/goss
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019:     Directory: C:\tmp\goss
    vhd-windows-2019:
    vhd-windows-2019:
    vhd-windows-2019: Mode                LastWriteTime         Length Name
    vhd-windows-2019: ----                -------------         ------ ----
    vhd-windows-2019: d-----       12/17/2020   6:37 PM                goss
    vhd-windows-2019:
    vhd-windows-2019:
==> vhd-windows-2019: 
==> vhd-windows-2019: 
==> vhd-windows-2019: 
==> vhd-windows-2019: Running goss tests...
==> vhd-windows-2019: Running GOSS render command: cd /tmp/goss && set "GOSS_USE_ALPHA=1" &&  /tmp/goss-windows-amd64.exe --gossfile goss/goss.yaml --vars /tmp/goss/goss-vars.yaml --vars-inline {"ARCH":"amd64","OS":"windows","PROVIDER":"azure","containerd_version":"1.4.3","kubernetes_cni_source_type":"","kubernetes_cni_version":"","kubernetes_source_type":"pkg","kubernetes_version":"v1.17.11"} render > /tmp/goss-spec.yaml
==> vhd-windows-2019: Goss render ran successfully
==> vhd-windows-2019: Running GOSS render debug command: cd /tmp/goss && set "GOSS_USE_ALPHA=1" &&  /tmp/goss-windows-amd64.exe --gossfile goss/goss.yaml --vars /tmp/goss/goss-vars.yaml --vars-inline {"ARCH":"amd64","OS":"windows","PROVIDER":"azure","containerd_version":"1.4.3","kubernetes_cni_source_type":"","kubernetes_cni_version":"","kubernetes_source_type":"pkg","kubernetes_version":"v1.17.11"} render -d > /tmp/debug-goss-spec.yaml
==> vhd-windows-2019: Goss render debug ran successfully
==> vhd-windows-2019: Running GOSS validate command: cd /tmp/goss &&  set "GOSS_USE_ALPHA=1" &&  /tmp/goss-windows-amd64.exe --gossfile goss/goss.yaml --vars /tmp/goss/goss-vars.yaml --vars-inline {"ARCH":"amd64","OS":"windows","PROVIDER":"azure","containerd_version":"1.4.3","kubernetes_cni_source_type":"","kubernetes_cni_version":"","kubernetes_source_type":"pkg","kubernetes_version":"v1.17.11"} validate --retry-timeout 0s --sleep 1s -f json -o pretty
    vhd-windows-2019: {
    vhd-windows-2019:     "results": [
    vhd-windows-2019:         {
    vhd-windows-2019:             "duration": 1587645100,
    vhd-windows-2019:             "err": null,
    vhd-windows-2019:             "expected": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "found": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "human": "",
    vhd-windows-2019:             "meta": null,
    vhd-windows-2019:             "property": "exit-status",
    vhd-windows-2019:             "resource-id": "kubectl.exe version --short --client=true -o json | powershell -Command \"($input | convertfrom-json).clientVersion.gitVersion\"",
    vhd-windows-2019:             "resource-type": "Command",
    vhd-windows-2019:             "result": 0,
    vhd-windows-2019:             "successful": true,
    vhd-windows-2019:             "summary-line": "Command: kubectl.exe version --short --client=true -o json | powershell -Command \"($input | convertfrom-json).clientVersion.gitVersion\": exit-status: matches expectation: [0]",
    vhd-windows-2019:             "test-type": 0,
    vhd-windows-2019:             "title": ""
    vhd-windows-2019:         },
    vhd-windows-2019:         {
    vhd-windows-2019:             "duration": 1587645100,
    vhd-windows-2019:             "err": null,
    vhd-windows-2019:             "expected": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "found": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "human": "",
    vhd-windows-2019:             "meta": null,
    vhd-windows-2019:             "property": "exit-status",
    vhd-windows-2019:             "resource-id": "kubeadm.exe version -o json | powershell -Command \"($input | convertfrom-json).clientVersion.gitVersion\"",
    vhd-windows-2019:             "resource-type": "Command",
    vhd-windows-2019:             "result": 0,
    vhd-windows-2019:             "successful": true,
    vhd-windows-2019:             "summary-line": "Command: kubeadm.exe version -o json | powershell -Command \"($input | convertfrom-json).clientVersion.gitVersion\": exit-status: matches expectation: [0]",
    vhd-windows-2019:             "test-type": 0,
    vhd-windows-2019:             "title": ""
    vhd-windows-2019:         },
    vhd-windows-2019:         {
    vhd-windows-2019:             "duration": 1822111700,
    vhd-windows-2019:             "err": null,
    vhd-windows-2019:             "expected": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "found": [
    vhd-windows-2019:                 "0"
    vhd-windows-2019:             ],
    vhd-windows-2019:             "human": "",
    vhd-windows-2019:             "meta": null,
    vhd-windows-2019:             "property": "exit-status",
    vhd-windows-2019:             "resource-id": "kubelet.exe --version | powershell -command \"$input\".Split(\" \")[1]",
    vhd-windows-2019:             "resource-type": "Command",
    vhd-windows-2019:             "result": 0,
    vhd-windows-2019:             "successful": true,
    vhd-windows-2019:             "summary-line": "Command: kubelet.exe --version | powershell -command \"$input\".Split(\" \")[1]: exit-status: matches expectation: [0]",
    vhd-windows-2019:             "test-type": 0,
    vhd-windows-2019:             "title": ""
    vhd-windows-2019:         }
    vhd-windows-2019:     ],
    vhd-windows-2019:     "summary": {
    vhd-windows-2019:         "failed-count": 0,
    vhd-windows-2019:         "summary-line": "Count: 3, Failed: 0, Duration: 1.822s",
    vhd-windows-2019:         "test-count": 3,
    vhd-windows-2019:         "total-duration": 1822111700
    vhd-windows-2019:     }
    vhd-windows-2019: }
==> vhd-windows-2019: Goss validate ran successfully
==> vhd-windows-2019: 
==> vhd-windows-2019: 
==> vhd-windows-2019: 
==> vhd-windows-2019: Downloading spec file and debug info
    vhd-windows-2019: Downloading Goss specs from, /tmp/goss-spec.yaml and /tmp/debug-goss-spec.yaml to current dir

@jsturtevant
Copy link
Contributor Author

@fishnix would you be able to help?

@fishnix
Copy link
Contributor

fishnix commented Jan 21, 2021

Hi @jsturtevant, thanks for the PR! I'll find some cycles to review.

Copy link
Contributor

@fishnix fishnix left a comment

Choose a reason for hiding this comment

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

Thanks again for submitting this PR. I had a few comments/suggestions. I was going to ask you to change the variable name to target_os until I noticed we've been entirely inconsistent with those properties 🤦 targetOs works. Cheers!

@@ -33,6 +40,7 @@ type GossConfig struct {
Password string
SkipInstall bool
Inspect bool
TargetOs OsType `string:"targetOs"`
Copy link
Contributor

Choose a reason for hiding this comment

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

this struct tag shouldn't be necessary

const (
Linux = OsType("Linux")
Windows = OsType("Windows")
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understand why you did this, but I'm inclined to simplify this and just use a string and get rid of the const. It will simplify the code below as well. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which logic? I think we still need all the checks in place as well as the ToLower to ensure the url is written properly. I could replace the OsType type and make it just a string?

arch := file[2]
if p.isGossAlpha() {
// includes .exe for windows
arch = file[3]
Copy link
Contributor

Choose a reason for hiding this comment

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

the comment confused me at first (I thought maybe this was only to support windows with the.exe - please strike it or clarify that the format of the alpha file is different.

if p.config.TargetOs != Linux && p.config.TargetOs != Windows {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Os must be %s or %s", Linux, Windows))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@jsturtevant
Copy link
Contributor Author

Thanks for finding the time to review! I addressed the comments. If I pushed a github action for building and running the tests on PR would you be interested?

@jsturtevant
Copy link
Contributor Author

output from a build:

==> vhd-windows-2019: Provisioning with Goss                                                                                                                                                                                                                
==> vhd-windows-2019: Configured to run on Windows 

//truncated

    vhd-windows-2019:     "summary": {
    vhd-windows-2019:         "failed-count": 0,
    vhd-windows-2019:         "summary-line": "Count: 3, Failed: 0, Duration: 2.648s",
    vhd-windows-2019:         "test-count": 3,
    vhd-windows-2019:         "total-duration": 2648382900
    vhd-windows-2019:     }
    vhd-windows-2019: }
==> vhd-windows-2019: Goss validate ran successfully

@jsturtevant
Copy link
Contributor Author

@fishnix Thanks for the initial review. I addressed most comments would you take a look again? Thanks!

@fishnix
Copy link
Contributor

fishnix commented Feb 23, 2021

@jsturtevant thanks for the fixes! 🙇 I'm sorry I haven't had a chance to review this. I will as soon as I can. Cheers!

@fishnix fishnix merged commit 0705d97 into YaleUniversity:master Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants