Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 730a92e

Browse files
committed
Add narrow object kinds
Signed-off-by: Tomasz Janiszewski <[email protected]>
1 parent 98ba3d9 commit 730a92e

File tree

10 files changed

+188
-13
lines changed

10 files changed

+188
-13
lines changed

pkg/objectkinds/cronjob.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package objectkinds
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime/schema"
5+
)
6+
7+
const (
8+
// CronJob represents Kubernetes CronJob objects.
9+
CronJob = "CronJob"
10+
)
11+
12+
func init() {
13+
RegisterObjectKind(CronJob, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
14+
return gvk == cronJobGVK
15+
}))
16+
}

pkg/objectkinds/daemonset.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package objectkinds
2+
3+
import (
4+
appsV1 "k8s.io/api/apps/v1"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
const (
9+
// DaemonSet represents Kubernetes DaemonSet objects.
10+
DaemonSet = "DaemonSet"
11+
)
12+
13+
var (
14+
daemonSetGVK = appsV1.SchemeGroupVersion.WithKind("DaemonSet")
15+
)
16+
17+
func init() {
18+
RegisterObjectKind(DaemonSet, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
19+
return gvk == daemonSetGVK
20+
}))
21+
}

pkg/objectkinds/deployment.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package objectkinds
2+
3+
import (
4+
appsV1 "k8s.io/api/apps/v1"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
const (
9+
// Deployment represents Kubernetes Deployment objects.
10+
Deployment = "Deployment"
11+
)
12+
13+
var (
14+
deploymentGVK = appsV1.SchemeGroupVersion.WithKind("Deployment")
15+
)
16+
17+
func init() {
18+
RegisterObjectKind(Deployment, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
19+
return gvk == deploymentGVK
20+
}))
21+
}

pkg/objectkinds/deployment_like.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@ package objectkinds
33
import (
44
"fmt"
55

6-
ocsAppsV1 "github.com/openshift/api/apps/v1"
7-
appsV1 "k8s.io/api/apps/v1"
8-
batchV1 "k8s.io/api/batch/v1"
9-
coreV1 "k8s.io/api/core/v1"
106
"k8s.io/apimachinery/pkg/runtime/schema"
117
)
128

139
var (
1410
deploymentLikeGroupKinds = func() map[schema.GroupKind]struct{} {
1511
m := make(map[schema.GroupKind]struct{})
1612
for _, gk := range []schema.GroupKind{
17-
{Group: appsV1.GroupName, Kind: "Deployment"},
18-
{Group: appsV1.GroupName, Kind: "DaemonSet"},
19-
{Group: ocsAppsV1.GroupName, Kind: "DeploymentConfig"},
20-
{Group: appsV1.GroupName, Kind: "StatefulSet"},
21-
{Group: appsV1.GroupName, Kind: "ReplicaSet"},
22-
{Group: coreV1.GroupName, Kind: "Pod"},
23-
{Group: coreV1.GroupName, Kind: "ReplicationController"},
24-
{Group: batchV1.GroupName, Kind: "Job"},
25-
{Group: batchV1.GroupName, Kind: "CronJob"},
13+
jobGVK.GroupKind(),
14+
daemonSetGVK.GroupKind(),
15+
deploymentConfigGVK.GroupKind(),
16+
statefulSetGVK.GroupKind(),
17+
replicaSetGVK.GroupKind(),
18+
podGVK.GroupKind(),
19+
replicationControllerGVK.GroupKind(),
20+
jobGVK.GroupKind(),
21+
cronJobGVK.GroupKind(),
2622
} {
2723
if _, ok := m[gk]; ok {
2824
panic(fmt.Sprintf("group kind double-registered: %v", gk))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package objectkinds
2+
3+
import (
4+
ocsAppsV1 "github.com/openshift/api/apps/v1"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
const (
9+
// DeploymentConfig represents OpenShift DeploymentConfig objects.
10+
DeploymentConfig = "DeploymentConfig"
11+
)
12+
13+
var (
14+
deploymentConfigGVK = ocsAppsV1.SchemeGroupVersion.WithKind("DeploymentConfig")
15+
)
16+
17+
func init() {
18+
RegisterObjectKind(DeploymentConfig, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
19+
return gvk == deploymentConfigGVK
20+
}))
21+
}

pkg/objectkinds/job.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package objectkinds
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime/schema"
5+
)
6+
7+
const (
8+
// Job represents Kubernetes Job objects.
9+
Job = "Job"
10+
)
11+
12+
func init() {
13+
RegisterObjectKind(Job, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
14+
return gvk == jobGVK
15+
}))
16+
}

pkg/objectkinds/pod.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package objectkinds
2+
3+
import (
4+
coreV1 "k8s.io/api/core/v1"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
const (
9+
// Pod represents Kubernetes Pod objects.
10+
Pod = "Pod"
11+
)
12+
13+
var (
14+
podGVK = coreV1.SchemeGroupVersion.WithKind("Pod")
15+
)
16+
17+
func init() {
18+
RegisterObjectKind(Pod, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
19+
return gvk == podGVK
20+
}))
21+
}

pkg/objectkinds/replicaset.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package objectkinds
2+
3+
import (
4+
appsV1 "k8s.io/api/apps/v1"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
const (
9+
// ReplicaSet represents Kubernetes ReplicaSet objects.
10+
ReplicaSet = "ReplicaSet"
11+
)
12+
13+
var (
14+
replicaSetGVK = appsV1.SchemeGroupVersion.WithKind("ReplicaSet")
15+
)
16+
17+
func init() {
18+
RegisterObjectKind(ReplicaSet, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
19+
return gvk == replicaSetGVK
20+
}))
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package objectkinds
2+
3+
import (
4+
coreV1 "k8s.io/api/core/v1"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
const (
9+
// ReplicationController represents Kubernetes ReplicationController objects.
10+
ReplicationController = "ReplicationController"
11+
)
12+
13+
var (
14+
replicationControllerGVK = coreV1.SchemeGroupVersion.WithKind("ReplicationController")
15+
)
16+
17+
func init() {
18+
RegisterObjectKind(ReplicationController, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
19+
return gvk == replicationControllerGVK
20+
}))
21+
}

pkg/objectkinds/statefulset.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package objectkinds
2+
3+
import (
4+
appsV1 "k8s.io/api/apps/v1"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
const (
9+
// StatefulSet represents Kubernetes StatefulSet objects.
10+
StatefulSet = "StatefulSet"
11+
)
12+
13+
var (
14+
statefulSetGVK = appsV1.SchemeGroupVersion.WithKind("StatefulSet")
15+
)
16+
17+
func init() {
18+
RegisterObjectKind(StatefulSet, MatcherFunc(func(gvk schema.GroupVersionKind) bool {
19+
return gvk == statefulSetGVK
20+
}))
21+
}

0 commit comments

Comments
 (0)