How to resolve "the object has been modified; please apply your changes to the latest version and try again" error when running oc apply command in RHOCP 4

Solution Unverified - Updated -

Issue

  • How to resolve "the object has been modified; please apply your changes to the latest version and try again" error when running oc apply command?

    $ oc new-project test
    $ oc new-app httpd
    
    $ oc get deployment httpd -o yaml > deployment.yaml
    $ vi deployment.yaml
        spec:
          containers:
            env:             <-- add
            - name: FOO      <-- add
              value: bar     <-- add
    
    $ oc apply -f deployment.yaml
    deployment.apps/httpd configured
    
    $ oc get deployment httpd -o yaml > deployment.yaml
    $ oc edit deployment httpd
            env:
            - name: FOO      <-- change to FOO1
              value: bar     <-- change to bar1
    
    deployment.apps/httpd edited
    
    $ vi deployment.yaml
            env:
            - name: FOO      <-- change to FOO2
              value: bar     <-- change to bar2
    
    $ oc apply -f deployment.yaml
    
    Error from server (Conflict): error when applying patch:
    to:
    Resource: "apps/v1, Resource=deployments", GroupVersionKind: "apps/v1, Kind=Deployment"
    Name: "httpd", Namespace: "test"
    for: "deployment.yaml": Operation cannot be fulfilled on deployments.apps "httpd": the object has been modified; please 
    apply your changes to the latest version and try again
    

Environment

  • Red Hat OpenShift Container Platform (RHOCP)
    • 4

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content