Karmadactl Usage Conventions

Recommended usage conventions for karmadactl.

karmadactl interpret

Preparation for YAML file

observed-deploy-nginx.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: nginx
  5. labels:
  6. app: nginx
  7. spec:
  8. replicas: 3
  9. paused: true
  10. selector:
  11. matchLabels:
  12. app: nginx
  13. template:
  14. metadata:
  15. labels:
  16. app: nginx
  17. spec:
  18. nodeSelector:
  19. foo: bar
  20. containers:
  21. - image: nginx
  22. name: nginx
  23. resources:
  24. limits:
  25. cpu: 100m
  26. status:
  27. availableReplicas: 2
  28. observedGeneration: 1
  29. readyReplicas: 2
  30. replicas: 2
  31. updatedReplicas: 2
  32. ``` desired-deploy-nginx.yaml

apiVersion: apps/v1 kind: Deployment metadata: name: nginx labels: app: nginx spec: replicas: 3 paused: false selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers:

  1. - image: nginx
  2. name: nginx
  3. serviceAccountName: test-sa

apiVersion: config.karmada.io/v1alpha1 kind: ResourceInterpreterCustomization metadata: name: declarative-configuration-example spec: target: apiVersion: apps/v1 kind: Deployment customizations: replicaResource: luaScript: > local kube = require(“kube”) function GetReplicas(obj) replica = obj.spec.replicas requirement = kube.accuratePodRequirements(obj.spec.template) return replica, requirement end replicaRevision: luaScript: > function ReviseReplica(obj, desiredReplica) obj.spec.replicas = desiredReplica return obj end retention: luaScript: > function Retain(desiredObj, observedObj) desiredObj.spec.paused = observedObj.spec.paused return desiredObj end statusAggregation: luaScript: > function AggregateStatus(desiredObj, statusItems) if statusItems == nil then return desiredObj end if desiredObj.status == nil then desiredObj.status = {} end replicas = 0 for i = 1, #statusItems do if statusItems[i].status ~= nil and statusItems[i].status.replicas ~= nil then replicas = replicas + statusItems[i].status.replicas end end desiredObj.status.replicas = replicas return desiredObj end statusReflection: luaScript: > function ReflectStatus (observedObj) return observedObj.status end healthInterpretation: luaScript: > function InterpretHealth(observedObj) return observedObj.status.readyReplicas == observedObj.spec.replicas end dependencyInterpretation: luaScript: > local kube = require(“kube”) function GetDependencies(desiredObj) refs = kube.getPodDependencies(desiredObj.spec.template, desiredObj.metadata.namespace) return refs end

applied: true clusterName: member1 health: Healthy status: availableReplicas: 1 readyReplicas: 1 replicas: 1

updatedReplicas: 1

applied: true clusterName: member2 health: Healthy status: availableReplicas: 1 readyReplicas: 1 replicas: 1 updatedReplicas: 1

  1. ### Validate the ResourceInterpreterCustomization configuration

karmadactl interpret -f resourceinterpretercustomization.yaml —check

  1. ### Execute the ResourceInterpreterCustomization with operation
  2. #### Execute the InterpretReplica rule

karmadactl interpret -f resourceinterpretercustomization.yaml —observed-file observed-deploy-nginx.yaml —operation=InterpretReplica

  1. #### Execute the Retain rule

karmadactl interpret -f resourceinterpretercustomization.yaml —desired-file desired-deploy-nginx.yaml —observed-file observed-deploy-nginx.yaml —operation Retain

  1. #### Execute the ReviseReplica rule

karmadactl interpret -f resourceinterpretercustomization.yaml —desired-replica 3 —observed-file observed-deploy-nginx.yaml —operation ReviseReplica

  1. #### Execute the InterpretStatus rule

karmadactl interpret -f resourceinterpretercustomization.yaml —observed-file observed-deploy-nginx.yaml —operation InterpretStatus

  1. #### Execute the InterpretHealth rule

karmadactl interpret -f resourceinterpretercustomization.yaml —observed-file observed-deploy-nginx.yaml —operation InterpretHealth

  1. #### Execute the InterpretDependency rule

karmadactl interpret -f resourceinterpretercustomization.yaml —desired-file desired-deploy-nginx.yaml —operation InterpretDependency

  1. #### Execute the AggregateStatus rule

karmadactl interpret -f resourceinterpretercustomization.yaml —desired-file desired-deploy-nginx.yaml —operation AggregateStatus —status-file status-file.yaml ```