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

Kubernetes Extensibility core/Service@v1 has incorrect type for targetPort in VS Code extension #9704

Open
AaronCrawfis opened this issue Jan 31, 2023 · 7 comments

Comments

@AaronCrawfis
Copy link

Bicep version

Bicep VSCode extension: v0.13.1
Bicep binary: Bicep CLI version 0.13.1 (e3ac80d678)

Describe the bug

spec.ports.targetPort has an incorrect type. It expects a string, however it should be an int instead.

Here's a valid template that deploys correctly:

import '[email protected]' with {
  kubeConfig: kubeConfig
  namespace: 'default'
}

resource frontendService 'core/Service@v1' = {
  metadata: {
    name: 'frontend'
    labels: {
      app: 'frontend'
    }
  }
  spec: {
    selector: {
      app: 'frontend'
    }
    ports: [
      {
        port: 80
        targetPort: 80 // The tooling expects this to be a string instead of an int
        protocol: 'TCP'
      }
    ]
    type: 'LoadBalancer'
  }
}

However I get the following warning:

image

When a string is used for deployment as suggested by the tooling, the following error is returned:

ERROR: ***"status":"Failed","error":***"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[***"code":"BadRequest","message":"***\r\n  \"error\": ***\r\n    \"code\": \"InvalidTemplateDeployment\",\r\n    \"message\": \"The template deployment 'frontend' is not valid according to the validation procedure. The tracking id is 'ecb95883-861b-45f5-a8f4-057e19cd5e5a'. See inner errors for details.\",\r\n    \"details\": [\r\n      ***\r\n        \"code\": \"UnprocessableEntity\",\r\n        \"target\": \"/resources/frontendService\",\r\n        \"message\": \"***\\\"kind\\\":\\\"Status\\\",\\\"apiVersion\\\":\\\"v1\\\",\\\"metadata\\\":***,\\\"status\\\":\\\"Failure\\\",\\\"message\\\":\\\"Service \\\\\\\"frontend\\\\\\\" is invalid: spec.ports[0].targetPort: Invalid value: \\\\\\\"80\\\\\\\": must contain at least one letter or number (a-z, 0-9)\\\",\\\"reason\\\":\\\"Invalid\\\",\\\"details\\\":***\\\"name\\\":\\\"frontend\\\",\\\"kind\\\":\\\"Service\\\",\\\"causes\\\":[***\\\"reason\\\":\\\"FieldValueInvalid\\\",\\\"message\\\":\\\"Invalid value: \\\\\\\"80\\\\\\\": must contain at least one letter or number (a-z, 0-9)\\\",\\\"field\\\":\\\"spec.ports[0].targetPort\\\"***]***,\\\"code\\\":422***\\n\"\r\n      ***\r\n    ]\r\n  ***\r\n***"***]***

To Reproduce

Paste the above Bicep into VSCode and see the warning

Additional context
Add any other context about the problem here.

@ghost ghost added the Needs: Triage 🔍 label Jan 31, 2023
@alex-frankel
Copy link
Collaborator

@shenglol / @anthony-c-martin / @rynowak -- is this because the type definitions we get from kubernetes is incorrect? If so, what would the process be for correcting that?

@rynowak
Copy link
Contributor

rynowak commented Feb 7, 2023

This is actually a gap in either Bicep or the tools to extract the types and put them in Bicep. I don't remember which, I think I mentioned it in this issue: Azure/bicep-types#153

The actual type is intorstring a special type that Kubernetes defines as a union of int or string. See ports.targetPort in the official docs https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/#ServiceSpec

@rynowak
Copy link
Contributor

rynowak commented Feb 7, 2023

ints are more common than strings for this usecase so if someone is blocked, we should tweak the definition to mandate an int. However both are valid.

@justinmchase
Copy link

Where can I read more about this kubernetes import? Is this publicly available?

@shenglol
Copy link
Contributor

shenglol commented Feb 17, 2023

@justinmchase We'll announce public preview for the k8s provider next week. Documentations will be published. Stay tuned 🙂.

@justinmchase
Copy link

I was just wondering if it would be possible to put kubernetes resources in via bicep, came here looking for some clues only to find you're literally about to release it. You're like a mind reader! gj

@stephaniezyen stephaniezyen modified the milestones: v0.15, v0.16 Mar 6, 2023
@stephaniezyen stephaniezyen modified the milestones: v0.16, v0.17 Mar 30, 2023
@alex-frankel alex-frankel modified the milestones: v0.17, v0.18 May 8, 2023
@shenglol
Copy link
Contributor

shenglol commented May 17, 2023

Unfortunately, the current limitations of the OpenAPI spec v2 and Bicep prevent us from resolving the issue with the IntOrString problem at this time. The union type int | string cannot be directly expressed in the OpenAPI spec v2, and it is also not allowed in Bicep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Blocked
Development

No branches or pull requests

6 participants