0
votes

I'm attempting to edit the yaml of a deployment config in the OpenShift web console.

I'm simply trying to add a command and some args. I have another working example with the correct syntax and indentation.

However, when I copy this into the deployment config, Im unable to save it due to a validation error. However the error doesnt relate to the change I've made.

The error message is:

Failed to process the resource. Reason: DeploymentConfig.apps.openshift.io "my-sdk" is invalid: [spec.template.spec.containers[0].name: Required value, spec.template.spec.containers[0].image: Required value]

For example, I have the following snippet from the working deployment config:

    spec:
      containers:
        - env:
            - name: MY_DB_HOST
              value: postgresql
            - name: MY_DB_NAME
              value: MY
            - name: MY_DB_PASSWORD
              value: MY
            - name: MY_DB_USER
              value: MY
            - name: MY_CACHE_ENABLED
              value: 'false'
          image: >-
            172.30.1.1:5000/myapp/my-sdk@sha256:eb485f011eaab9342b7fcf272c9f22dded9c238987f1dec932f8e1640ac18251
          imagePullPolicy: Always
          name: my-sdk
          ports:
            - containerPort: 8080
              protocol: TCP

Then I attempt to change it to the following:

    spec:
      containers:
        - args:
            - '-myarg'
          command:
            - node
        - env:
            - name: MY_DB_HOST
              value: postgresql
            - name: MY_DB_NAME
              value: MY
            - name: MY_DB_PASSWORD
              value: MY
            - name: MY_DB_USER
              value: MY
            - name: MY_CACHE_ENABLED
              value: 'false'
          image: >-
            172.30.1.1:5000/myapp/my-sdk@sha256:eb485f011eaab9342b7fcf272c9f22dded9c238987f1dec932f8e1640ac18251
          imagePullPolicy: Always
          name: my-sdk
          ports:
            - containerPort: 8080
              protocol: TCP

And with this change I get the above error. I'm 99% certain the change I made is valid, as I'm simply coping it from a functional deployment config. And the error message doesnt seem to relate at all to the change.

Update

Now I have a working deploymentconfig that contains command and arg values.

When I try to remove these, without modifying any other yaml, or indentation, I get the following useless validation error:

Failed to process the resource. Reason: ReplicationController in version "v1" cannot be handled as a ReplicationController: v1.ReplicationController.Spec: v1.ReplicationControllerSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.TerminationGracePeriodSeconds: SecurityContext: SchedulerName: RestartPolicy: DNSPolicy: Containers: decode slice: expect [ or n, but found {, error found in #10 byte of ...|y":"File"},"dnsPolic|..., bigger context ...|ermination-log","terminationMessagePolicy":"File"},"dnsPolicy":"ClusterFirst","restartPolicy":"Alway|...

2
The whole env and args sections needs to be indented one more level. The '-' for those should be same indent as command. - Graham Dumpleton
It can sometimes be helpful to plugin what you want to use into json2yaml.com and look at the result in JSON as it more clearly shows the structure if you are not familiar with YAML. - Graham Dumpleton
Please update your new yaml file. Please provide your openshift and kubernetes versions. - Mark

2 Answers

0
votes

One example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451
        env:
         - name: DEMO_GREETING
           value: "Hello from the environment"
        command: ["echo"]
        args: ["$(GREETING) $(HONORIFIC) $(NAME)"] 
        ports:
        - containerPort: 80

Please follow documentation: Using environment variables inside of your config

In addition please verify your spec with the image line image: >- as per error image: Required value

0
votes

In ReplicationController they should have selector (In RC Spec) and labels ( template spec) to match the container to start. Hence based on error you may not get to know this as this would be more of generic.