魔数、默认值使用常量封装:唯一来源

魔数、默认值使用常量封装。提高可读性,统一定义唯一来源,唯一来源相当于是统一了标准。常量在离使用代码最近的地方定义比较好。 现象 const ( // NamespaceDefault means the object is in the default namespace which is applied when not specified by clients NamespaceDefault string = "default" // NamespaceAll is the default argument to specify on a context when you want to list or filter resources across all namespaces NamespaceAll string = "" // NamespaceNodeLease is the namespace where we place node lease objects (used for node heartbeats) NamespaceNodeLease string = "kube-node-lease" ) 这是 k8s 的 core 的 type 资源定义。 ...

March 28, 2026 · 1 min · 99 words · 文叨叨