mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge pull request #132 from Liujingfang1/order
correct ordering of the k8s objects
This commit is contained in:
@@ -1,4 +1,72 @@
|
|||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: cockroachdb
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: Role
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: cockroachdb
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
resources:
|
||||||
|
- secrets
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- get
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: cockroachdb
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- certificates.k8s.io
|
||||||
|
resources:
|
||||||
|
- certificatesigningrequests
|
||||||
|
verbs:
|
||||||
|
- create
|
||||||
|
- get
|
||||||
|
- watch
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: RoleBinding
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: cockroachdb
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Role
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
namespace: default
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: cockroachdb
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: dev-base-cockroachdb
|
||||||
|
namespace: default
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
@@ -38,13 +106,6 @@ spec:
|
|||||||
selector:
|
selector:
|
||||||
app: cockroachdb
|
app: cockroachdb
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
|
||||||
kind: ServiceAccount
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: cockroachdb
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
---
|
|
||||||
apiVersion: apps/v1beta1
|
apiVersion: apps/v1beta1
|
||||||
kind: StatefulSet
|
kind: StatefulSet
|
||||||
metadata:
|
metadata:
|
||||||
@@ -142,64 +203,3 @@ spec:
|
|||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: cockroachdb
|
app: cockroachdb
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
|
||||||
kind: ClusterRole
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: cockroachdb
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
rules:
|
|
||||||
- apiGroups:
|
|
||||||
- certificates.k8s.io
|
|
||||||
resources:
|
|
||||||
- certificatesigningrequests
|
|
||||||
verbs:
|
|
||||||
- create
|
|
||||||
- get
|
|
||||||
- watch
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
|
||||||
kind: ClusterRoleBinding
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: cockroachdb
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
roleRef:
|
|
||||||
apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: ClusterRole
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
subjects:
|
|
||||||
- kind: ServiceAccount
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
namespace: default
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
|
||||||
kind: Role
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: cockroachdb
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
rules:
|
|
||||||
- apiGroups:
|
|
||||||
- ""
|
|
||||||
resources:
|
|
||||||
- secrets
|
|
||||||
verbs:
|
|
||||||
- create
|
|
||||||
- get
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
|
||||||
kind: RoleBinding
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: cockroachdb
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
roleRef:
|
|
||||||
apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Role
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
subjects:
|
|
||||||
- kind: ServiceAccount
|
|
||||||
name: dev-base-cockroachdb
|
|
||||||
namespace: default
|
|
||||||
|
|||||||
@@ -37,12 +37,27 @@ func (a IdSlice) Less(i, j int) bool {
|
|||||||
return a[i].Name() < a[j].Name()
|
return a[i].Name() < a[j].Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func gvkLess(i, j schema.GroupVersionKind) bool {
|
var order = []string{"Namespace", "CustomResourceDefinition", "ServiceAccount",
|
||||||
if i.Kind == "Namespace" {
|
"Role", "ClusterRole", "RoleBinding", "ClusterRoleBinding"}
|
||||||
return true
|
var typeOrders = func() map[string]int {
|
||||||
} else if j.Kind == "Namespace" {
|
m := map[string]int{}
|
||||||
return false
|
for i, n := range order {
|
||||||
} else {
|
m[n] = i
|
||||||
return i.String() < j.String()
|
|
||||||
}
|
}
|
||||||
|
return m
|
||||||
|
}()
|
||||||
|
|
||||||
|
func gvkLess(i, j schema.GroupVersionKind) bool {
|
||||||
|
indexi, foundi := typeOrders[i.Kind]
|
||||||
|
indexj, foundj := typeOrders[j.Kind]
|
||||||
|
if foundi && foundj {
|
||||||
|
return indexi < indexj
|
||||||
|
}
|
||||||
|
if foundi && !foundj {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if !foundi && foundj {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return i.String() < j.String()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,18 @@ func TestLess(t *testing.T) {
|
|||||||
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"),
|
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"),
|
||||||
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"),
|
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"),
|
||||||
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"),
|
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"),
|
||||||
|
resource.NewResId(schema.GroupVersionKind{Kind: "Role"}, "ro"),
|
||||||
|
resource.NewResId(schema.GroupVersionKind{Kind: "RoleBinding"}, "rb"),
|
||||||
|
resource.NewResId(schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, "crd"),
|
||||||
|
resource.NewResId(schema.GroupVersionKind{Kind: "ServiceAccount"}, "sa"),
|
||||||
}
|
}
|
||||||
expected := IdSlice{
|
expected := IdSlice{
|
||||||
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"),
|
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"),
|
||||||
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"),
|
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"),
|
||||||
|
resource.NewResId(schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, "crd"),
|
||||||
|
resource.NewResId(schema.GroupVersionKind{Kind: "ServiceAccount"}, "sa"),
|
||||||
|
resource.NewResId(schema.GroupVersionKind{Kind: "Role"}, "ro"),
|
||||||
|
resource.NewResId(schema.GroupVersionKind{Kind: "RoleBinding"}, "rb"),
|
||||||
resource.NewResId(schema.GroupVersionKind{Kind: "ConfigMap"}, "cm"),
|
resource.NewResId(schema.GroupVersionKind{Kind: "ConfigMap"}, "cm"),
|
||||||
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"),
|
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user