Skip to content

Exec generator plugins do not work on Windows #4213

@mprahl

Description

@mprahl

Describe the bug

I'm unable to use an exec Kustomize generator plugin on Windows. This works for me both on Linux and MacOS.

The error is as follows:

C:\Users\mprahl\Desktop\kustomize>kustomize build --enable-alpha-plugins
Error: failure in plugin configured via C:\Users\mprahl\AppData\Local\Temp\kust-plugin-config-171892711; exec: "C:\\Users\\mprahl\\kustomize\\plugin\\policy.open-cluster-management.io\\v1\\policygenerator\\PolicyGenerator": file does not exist: exec: "C:\\Users\\mprahl\\kustomize\\plugin\\policy.open-cluster-management.io\\v1\\policygenerator\\PolicyGenerator": file does not exist

However, the generator executable does exist:

C:\Users\mprahl\Desktop\kustomize>dir "C:\Users\mprahl\kustomize\plugin\policy.open-cluster-management.io\v1\policygenerator\PolicyGenerator"
 Volume in drive C has no label.
 Volume Serial Number is F848-3479
 
 Directory of C:\Users\mprahl\kustomize\plugin\policy.open-cluster-management.io\v1\policygenerator
 
09/28/2021  07:46 AM        18,222,080 PolicyGenerator
               1 File(s)     18,222,080 bytes
               0 Dir(s)   7,268,851,712 bytes free

Here is how I can reproduce it:

  1. Download the precompiled binary or compile it from source.
  2. Run the following PowerShell commands to get the plugin in the correct location:
    $pluginDir = Join-Path (Get-Item Env:\USERPROFILE).Value "kustomize\plugin\policy.open-cluster-management.io\v1\policygenerator"
    New-Item -Path $pluginDir -ItemType Directory
    $downloadPath = Join-Path (Get-Item Env:\USERPROFILE).Value "Downloads\windows-amd64-PolicyGenerator.exe"
    Move-Item $downloadPath (Join-Path $pluginDir "PolicyGenerator")
  3. Create the following files:
    • kustomization.yaml
      generators:
        - policyGenerator.yaml
    • policyGenerator.yaml
      apiVersion: policy.open-cluster-management.io/v1
      kind: PolicyGenerator
      metadata:
        name: policy-generator-name
      policyDefaults:
        namespace: my-policies
      policies:
        - name: policy-app-config-aliens 
          manifests:
             - path: configmap.yaml
    • configmap.yaml
      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: game-config-aliens
        namespace: default
      data:
        game.properties: |
          enemies=aliens
        ui.properties: |
          color.good=purple
  4. Run kustomize with kustomize build --enable-alpha-plugins

Expected output

apiVersion: apps.open-cluster-management.io/v1
kind: PlacementRule
metadata:
  name: placement-policy-app-config-aliens
  namespace: my-policies
spec:
  clusterConditions:
  - status: "True"
    type: ManagedClusterConditionAvailable
  clusterSelector:
    matchExpressions: []
---
apiVersion: policy.open-cluster-management.io/v1
kind: PlacementBinding
metadata:
  name: binding-policy-app-config-aliens
  namespace: my-policies
placementRef:
  apiGroup: apps.open-cluster-management.io
  kind: PlacementRule
  name: placement-policy-app-config-aliens
subjects:
- apiGroup: policy.open-cluster-management.io
  kind: Policy
  name: policy-app-config-aliens
---
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
  annotations:
    policy.open-cluster-management.io/categories: CM Configuration Management
    policy.open-cluster-management.io/controls: CM-2 Baseline Configuration
    policy.open-cluster-management.io/standards: NIST SP 800-53
  name: policy-app-config-aliens
  namespace: my-policies
spec:
  disabled: false
  policy-templates:
  - objectDefinition:
      apiVersion: policy.open-cluster-management.io/v1
      kind: ConfigurationPolicy
      metadata:
        name: policy-app-config-aliens
      spec:
        object-templates:
        - complianceType: musthave
          objectDefinition:
            apiVersion: v1
            data:
              game.properties: |
                enemies=aliens
              ui.properties: |
                color.good=purple
            kind: ConfigMap
            metadata:
              name: game-config-aliens
              namespace: default
        remediationAction: inform
        severity: low

Actual output

C:\Users\mprahl\Desktop\kustomize>kustomize build --enable-alpha-plugins
Error: failure in plugin configured via C:\Users\mprahl\AppData\Local\Temp\kust-plugin-config-171892711; exec: "C:\\Users\\mprahl\\kustomize\\plugin\\policy.open-cluster-management.io\\v1\\policygenerator\\PolicyGenerator": file does not exist: exec: "C:\\Users\\mprahl\\kustomize\\plugin\\policy.open-cluster-management.io\\v1\\policygenerator\\PolicyGenerator": file does not exist

Kustomize version

  • I used the latest v4 compiled from source as of September 28th, 2021
  • I also tried a precompiled v4.1.3

Platform

Windows

Additional context

It seems that Kustomize finds the binary before executing the generator plugin because the following error is printed when the binary is just flat out missing:

Error: loading generator plugins: expected file with Go object code at: C:\Users\mprahl\kustomize\plugin\policy.open-cluster-management.io\v1\policygenerator\PolicyGenerator.so

It seems that the code actually executing the binary has an issue on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions