How to delete podAntiAfinity in Openshift
Asked Answered
T

1

5

I need to delete the podeAntiAfinity property from multiple deployment configs.

So far I've manage to find a way to update this property using the oc patch dc.

My deployment config looks like something like this:

apiVersion: v1
kind: DeploymentConfig
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftNewApp
  creationTimestamp: 2018-05-25T17:31:47Z
  generation: 8
  labels:
    app: my-app
  name: my-dc
  namespace: my-ns
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    app: my-app
    deploymentconfig: my-dc
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 1
      maxUnavailable: 100%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      annotations:
        alpha.image.policy.openshift.io/resolve-names: '*'
        openshift.io/generated-by: OpenShiftNewApp
      creationTimestamp: null
      labels:
        app: my-app
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: someKey
                operator: DoesNotExist
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - another-app
            topologyKey: kubernetes.io/hostname

I would like to remove the spec.template.spec.affinity.podAntiAffinity while keeping the spec.template.spec.affinity.nodeAffinity.

Could anybody help please?

Template answered 26/7, 2018 at 21:14 Comment(0)
C
9

The oc patch command takes different formats for the patch. You want to use the json format as that allows you to say that an item should be removed. See:

Untested guess, the patch would need to be:

[{ "op": "remove", "path": "/spec/template/spec/affinity/podAntiAffinity" }]

Thus try:

oc patch dc/my-dc --type json --patch '[{ "op": "remove", "path": "/spec/template/spec/affinity/podAntiAffinity" }]'
Complexion answered 26/7, 2018 at 23:14 Comment(1)
Great! that's realy what I wanted. Thanks!Template

© 2022 - 2024 — McMap. All rights reserved.