karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.48k stars 885 forks source link

make describe propagationpolicy show resource propagation status #4623

Open grosser opened 9 months ago

grosser commented 9 months ago

What would you like to be added: I want to know what is propagated by my policy and what the status of that propagation is (active or not) Ideally also propagation events/errors.

Why is this needed: Atm there is no nice way of viewing this and after changing a policy I wan to know if everything is ok.

POC script:

require_relative 'helpers'
require 'shellwords'
require 'json'

# see what policy the user requested
policy = JSON.parse(Helpers.kubectl("get #{ARGV.shelljoin} -o json"))
policy_name = policy.dig("metadata", "name")

# find all it's work
work = JSON.parse(Helpers.kubectl("get --raw /apis/work.karmada.io/v1alpha1/works")).fetch("items")
work.select! do |w|
  labels = w.dig("spec", "workload", "manifests", 0, "metadata", "labels")
  if (ns = policy.dig("metadata", "namespace"))
    labels["propagationpolicy.karmada.io/name"] == policy_name &&
      labels["propagationpolicy.karmada.io/namespace"] == ns
  else
    labels["clusterpropagationpolicy.karmada.io/name"] == policy_name
  end
end

# show work status
Helpers.table_print([["Name", "Namespace", "Applied"]] + work.map do |w|
  [
    w.dig("metadata", "name"),
    w.dig("metadata", "namespace"),
    w.dig("status", "conditions")&.detect { |c| c["type"] == "Applied" }&.dig("status").to_s
  ]
end)

gives:

Name                                  Namespace              Applied
kube-service-watcher-5d9dbfd89b       karmada-es-eks-sandbox True
kube-service-watcher-65c6f794b9       karmada-es-eks-sandbox True
kube-service-watcher-68fff77876       karmada-es-eks-sandbox True
kube-service-watcher-7bc5bc8f8f       karmada-es-eks-sandbox True
kube-service-watcher-864ffcc669       karmada-es-eks-sandbox True
kube-service-watcher-959957f6f        karmada-es-eks-sandbox True
kube-service-watcher-console-7f9bf749 karmada-es-eks-sandbox True
XiShanYongYe-Chang commented 4 months ago

Hi @grosser sorry for replying late. I see that in the script you provided, the goal is achieved by querying the status of the work, Is the information on the work insufficient?

grosser commented 4 months ago

the status on the work is good, but ideally it would be on the policy directly ... this might be hard to do, not sure, but for example nodes show their pods when they are described so I was hoping policies could do something similar because atm describing a policy does not really give an indication of how it's doing, you have to find all the work it spawned to see that

XiShanYongYe-Chang commented 4 months ago

Thanks @grosser

If we follow this idea, the effect will be really great.

However, I understand that policy is only a configuration rule, which should be stateless. The propagation status of resources should be associated with the resources themselves, such as ResourceBinding objects and Work objects. There is a higher layer of resources that represent the propagation of resources and may require more user case input to make a decision.

How do you think? @RainbowMango @chaunceyjiang @whitewindmills

grosser commented 4 months ago

so I get if it's not universally available, but maybe a karmadactl propagationstatus cpp abc, was mostly hoping that someone would reply with "here is how we do this" :)