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

Error when creating Service with a targetPort from Yaml #241

Closed
archcosmo opened this issue Apr 19, 2018 · 1 comment
Closed

Error when creating Service with a targetPort from Yaml #241

archcosmo opened this issue Apr 19, 2018 · 1 comment

Comments

@archcosmo
Copy link
Contributor

Creating a Service from a Yaml specficiation which specifies a targetPort:

try {
    CoreV1Api api = new CoreV1Api();
    String serviceYaml =
                        "apiVersion: v1\n" +
                        "kind: Service\n" +
                        "metadata:\n" +
                        "  name:\n" +
                        "    service-name\n" +
                        "spec:\n" +
                        "  ports:\n" +
                        "  - port: 1000\n" +
                        "    targetPort: 1000";
    V1Service service = YamlBugFix.loadAs(serviceYaml, V1Service.class);
    api.createNamespacedService("default", service, null); 
} catch (ApiException err) {
    System.out.println(err.getResponseBody());
}

results in the following error:

{
    "kind":"Status",
    "apiVersion":"v1",
    "metadata":{},
    "status":"Failure",
    "message":"Service \"service-name\" is invalid: spec.ports[0].targetPort: Invalid value: \"1000\": must contain at least one letter or number (a-z, 0-9)",
    "reason":"Invalid",
    "details": {
        "name":"service-name",
        "kind":"Service",
        "causes": [
            {
                "reason":"FieldValueInvalid",
                "message":"Invalid value: \"1000\": must contain at least one letter or number (a-z, 0-9)",
                "field":"spec.ports[0].targetPort"
            }
        ]
    },
    "code":422
}

This is because the Yaml loader defaults to the IntOrString(String) constructor, even when an integer is given in the Yaml spec.

archcosmo added a commit to archcosmo/kubernetes-client-java that referenced this issue Apr 19, 2018
archcosmo added a commit to archcosmo/kubernetes-client-java that referenced this issue Apr 19, 2018
archcosmo added a commit to archcosmo/kubernetes-client-java that referenced this issue Apr 19, 2018
archcosmo added a commit to archcosmo/kubernetes-client-java that referenced this issue Apr 20, 2018
brendandburns added a commit that referenced this issue Apr 20, 2018
Add custom Constructor to Yaml to fix issue #241
@brendandburns
Copy link
Contributor

Closing since #242 is merged.

jesmarsc referenced this issue in jesmarsc/kubernetes-konekt Jan 20, 2019
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

No branches or pull requests

2 participants