Skip to content

Commit b6a4304

Browse files
committed
api groups interesting changes
1 parent 2197571 commit b6a4304

File tree

26 files changed

+436
-245
lines changed

26 files changed

+436
-245
lines changed

pkg/api/meta/pods.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,24 @@ var resourcesToCheck = map[unversioned.GroupResource]unversioned.GroupKind{
2323
kapi.Resource("replicationcontrollers"): kapi.Kind("ReplicationController"),
2424
batch.Resource("jobs"): batch.Kind("Job"),
2525
batch.Resource("jobtemplates"): batch.Kind("JobTemplate"),
26+
2627
// TODO do we still need this or is cronjob sufficient?
27-
batch.Resource("scheduledjobs"): batch.Kind("ScheduledJob"),
28-
batch.Resource("cronjobs"): batch.Kind("CronJob"),
29-
extensions.Resource("deployments"): extensions.Kind("Deployment"),
30-
extensions.Resource("replicasets"): extensions.Kind("ReplicaSet"),
31-
extensions.Resource("jobs"): extensions.Kind("Job"),
32-
extensions.Resource("jobtemplates"): extensions.Kind("JobTemplate"),
33-
apps.Resource("statefulsets"): apps.Kind("StatefulSet"),
34-
deployapi.Resource("deploymentconfigs"): deployapi.Kind("DeploymentConfig"),
35-
securityapi.Resource("podsecuritypolicysubjectreviews"): securityapi.Kind("PodSecurityPolicySubjectReview"),
36-
securityapi.Resource("podsecuritypolicyselfsubjectreviews"): securityapi.Kind("PodSecurityPolicySelfSubjectReview"),
37-
securityapi.Resource("podsecuritypolicyreviews"): securityapi.Kind("PodSecurityPolicyReview"),
28+
batch.Resource("scheduledjobs"): batch.Kind("ScheduledJob"),
29+
batch.Resource("cronjobs"): batch.Kind("CronJob"),
30+
extensions.Resource("deployments"): extensions.Kind("Deployment"),
31+
extensions.Resource("replicasets"): extensions.Kind("ReplicaSet"),
32+
extensions.Resource("jobs"): extensions.Kind("Job"),
33+
extensions.Resource("jobtemplates"): extensions.Kind("JobTemplate"),
34+
apps.Resource("statefulsets"): apps.Kind("StatefulSet"),
35+
36+
deployapi.Resource("deploymentconfigs"): deployapi.Kind("DeploymentConfig"),
37+
deployapi.LegacyResource("deploymentconfigs"): deployapi.LegacyKind("DeploymentConfig"),
38+
securityapi.Resource("podsecuritypolicysubjectreviews"): securityapi.Kind("PodSecurityPolicySubjectReview"),
39+
securityapi.LegacyResource("podsecuritypolicysubjectreviews"): securityapi.LegacyKind("PodSecurityPolicySubjectReview"),
40+
securityapi.Resource("podsecuritypolicyselfsubjectreviews"): securityapi.Kind("PodSecurityPolicySelfSubjectReview"),
41+
securityapi.LegacyResource("podsecuritypolicyselfsubjectreviews"): securityapi.LegacyKind("PodSecurityPolicySelfSubjectReview"),
42+
securityapi.Resource("podsecuritypolicyreviews"): securityapi.Kind("PodSecurityPolicyReview"),
43+
securityapi.LegacyResource("podsecuritypolicyreviews"): securityapi.LegacyKind("PodSecurityPolicyReview"),
3844
}
3945

4046
// HasPodSpec returns true if the resource is known to have a pod spec.

pkg/api/validation/validation.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,17 @@ func GetRequiresNamespace(obj runtime.Object) (bool, error) {
128128
return false, err
129129
}
130130

131-
restMapping, err := registered.RESTMapper().RESTMapping(groupVersionKinds[0].GroupKind())
132-
if err != nil {
133-
return false, err
131+
for _, gvk := range groupVersionKinds {
132+
restMapping, err := registered.RESTMapper().RESTMapping(gvk.GroupKind())
133+
if err != nil {
134+
return false, err
135+
}
136+
if restMapping.Scope.Name() == meta.RESTScopeNameNamespace {
137+
return true, nil
138+
}
134139
}
135140

136-
return restMapping.Scope.Name() == meta.RESTScopeNameNamespace, nil
141+
return false, nil
137142
}
138143

139144
func HasObjectMeta(obj runtime.Object) bool {

pkg/build/admission/strategyrestrictions/admission.go

+22-11
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,14 @@ func NewBuildByStrategy() admission.Interface {
3636
}
3737
}
3838

39-
var (
40-
buildsResource = buildapi.Resource("builds")
41-
buildConfigsResource = buildapi.Resource("buildconfigs")
42-
)
43-
4439
func (a *buildByStrategy) Admit(attr admission.Attributes) error {
45-
if resource := attr.GetResource().GroupResource(); resource != buildsResource && resource != buildConfigsResource {
40+
gr := attr.GetResource().GroupResource()
41+
if !buildapi.IsResourceOrLegacy("buildconfigs", gr) && !buildapi.IsResourceOrLegacy("builds", gr) {
4642
return nil
4743
}
4844
// Explicitly exclude the builds/details subresource because it's only
4945
// updating commit info and cannot change build type.
50-
if attr.GetResource().GroupResource() == buildsResource && attr.GetSubresource() == "details" {
46+
if buildapi.IsResourceOrLegacy("builds", gr) && attr.GetSubresource() == "details" {
5147
return nil
5248
}
5349
switch obj := attr.GetObject().(type) {
@@ -134,14 +130,15 @@ func (a *buildByStrategy) checkBuildConfigAuthorization(buildConfig *buildapi.Bu
134130
}
135131

136132
func (a *buildByStrategy) checkBuildRequestAuthorization(req *buildapi.BuildRequest, attr admission.Attributes) error {
137-
switch attr.GetResource().GroupResource() {
138-
case buildsResource:
133+
gr := attr.GetResource().GroupResource()
134+
switch {
135+
case buildapi.IsResourceOrLegacy("builds", gr):
139136
build, err := a.client.Builds(attr.GetNamespace()).Get(req.Name)
140137
if err != nil {
141138
return admission.NewForbidden(attr, err)
142139
}
143140
return a.checkBuildAuthorization(build, attr)
144-
case buildConfigsResource:
141+
case buildapi.IsResourceOrLegacy("buildconfigs", gr):
145142
build, err := a.client.BuildConfigs(attr.GetNamespace()).Get(req.Name)
146143
if err != nil {
147144
return admission.NewForbidden(attr, err)
@@ -157,8 +154,22 @@ func (a *buildByStrategy) checkAccess(strategy buildapi.BuildStrategy, subjectAc
157154
if err != nil {
158155
return admission.NewForbidden(attr, err)
159156
}
157+
// If not allowed, try to check against the legacy resource
158+
// FIXME: Remove this when the legacy API is deprecated
160159
if !resp.Allowed {
161-
return notAllowed(strategy, attr)
160+
obj, err := kapi.Scheme.DeepCopy(subjectAccessReview)
161+
if err != nil {
162+
return admission.NewForbidden(attr, err)
163+
}
164+
legacySar := obj.(*authorizationapi.LocalSubjectAccessReview)
165+
legacySar.Action.Group = ""
166+
resp, err := a.client.LocalSubjectAccessReviews(attr.GetNamespace()).Create(legacySar)
167+
if err != nil {
168+
return admission.NewForbidden(attr, err)
169+
}
170+
if !resp.Allowed {
171+
return notAllowed(strategy, attr)
172+
}
162173
}
163174
return nil
164175
}

pkg/cmd/admin/migrate/migrator.go

+12
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ func (o *ResourceOptions) Complete(f *clientcmd.Factory, c *cobra.Command) error
153153
}
154154
exclude := sets.NewString()
155155
for _, gr := range o.DefaultExcludes {
156+
if len(o.OverlappingResources) > 0 {
157+
for _, others := range o.OverlappingResources {
158+
if !others.Has(gr.String()) {
159+
continue
160+
}
161+
exclude.Insert(others.List()...)
162+
break
163+
}
164+
}
156165
exclude.Insert(gr.String())
157166
}
158167
candidate := sets.NewString()
@@ -173,6 +182,9 @@ func (o *ResourceOptions) Complete(f *clientcmd.Factory, c *cobra.Command) error
173182
if !others.Has(k) {
174183
continue
175184
}
185+
// TODO: the order here is not deterministic, due to the fact that StringSet is
186+
// using map under the covers, so you may end up with a different resource being
187+
// used each time
176188
reduce = others.List()[0]
177189
break
178190
}

pkg/cmd/admin/migrate/storage/storage.go

+71-5
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,89 @@ func NewCmdMigrateAPIStorage(name, fullName string, f *clientcmd.Factory, in io.
6868

6969
Include: []string{"*"},
7070
DefaultExcludes: []unversioned.GroupResource{
71+
// openshift resources:
7172
{Resource: "appliedclusterresourcequotas"},
72-
{Resource: "bindings"},
73-
{Resource: "deploymentconfigrollbacks"},
74-
{Resource: "events"},
7573
{Resource: "imagestreamimages"}, {Resource: "imagestreamtags"}, {Resource: "imagestreammappings"}, {Resource: "imagestreamimports"},
7674
{Resource: "projectrequests"}, {Resource: "projects"},
77-
{Resource: "componentstatuses"},
7875
{Resource: "clusterrolebindings"}, {Resource: "rolebindings"},
7976
{Resource: "clusterroles"}, {Resource: "roles"},
8077
{Resource: "resourceaccessreviews"}, {Resource: "localresourceaccessreviews"}, {Resource: "subjectaccessreviews"},
8178
{Resource: "selfsubjectrulesreviews"}, {Resource: "localsubjectaccessreviews"},
79+
{Resource: "useridentitymappings"},
80+
{Resource: "podsecuritypolicyreviews"}, {Resource: "podsecuritypolicyselfsubjectreviews"}, {Resource: "podsecuritypolicysubjectreviews"},
81+
82+
// kubernetes resources:
83+
{Resource: "bindings"},
84+
{Resource: "deploymentconfigrollbacks"},
85+
{Resource: "events"},
86+
{Resource: "componentstatuses"},
8287
{Resource: "replicationcontrollerdummies.extensions"},
8388
{Resource: "podtemplates"},
84-
{Resource: "useridentitymappings"},
89+
{Resource: "selfsubjectaccessreviews", Group: "authorization.k8s.io"}, {Resource: "localsubjectaccessreviews", Group: "authorization.k8s.io"},
8590
},
8691
// Resources known to share the same storage
8792
OverlappingResources: []sets.String{
93+
// openshift resources:
94+
sets.NewString("deploymentconfigs.apps.openshift.io", "deploymentconfigs"),
95+
96+
sets.NewString("clusterpolicies.authorization.openshift.io", "clusterpolicies"),
97+
sets.NewString("clusterpolicybindings.authorization.openshift.io", "clusterpolicybindings"),
98+
sets.NewString("clusterrolebindings.authorization.openshift.io", "clusterrolebindings"),
99+
sets.NewString("clusterroles.authorization.openshift.io", "clusterroles"),
100+
sets.NewString("localresourceaccessreviews.authorization.openshift.io", "localresourceaccessreviews"),
101+
sets.NewString("localsubjectaccessreviews.authorization.openshift.io", "localsubjectaccessreviews"),
102+
sets.NewString("policies.authorization.openshift.io", "policies"),
103+
sets.NewString("policybindings.authorization.openshift.io", "policybindings"),
104+
sets.NewString("resourceaccessreviews.authorization.openshift.io", "resourceaccessreviews"),
105+
sets.NewString("rolebindingrestrictions.authorization.openshift.io", "rolebindingrestrictions"),
106+
sets.NewString("rolebindings.authorization.openshift.io", "rolebindings"),
107+
sets.NewString("roles.authorization.openshift.io", "roles"),
108+
sets.NewString("selfsubjectrulesreviews.authorization.openshift.io", "selfsubjectrulesreviews"),
109+
sets.NewString("subjectaccessreviews.authorization.openshift.io", "subjectaccessreviews"),
110+
sets.NewString("subjectrulesreviews.authorization.openshift.io", "subjectrulesreviews"),
111+
112+
sets.NewString("builds.build.openshift.io", "builds"),
113+
sets.NewString("buildconfigs.build.openshift.io", "buildconfigs"),
114+
115+
sets.NewString("images.image.openshift.io", "images"),
116+
sets.NewString("imagesignatures.image.openshift.io", "imagesignatures"),
117+
sets.NewString("imagestreamimages.image.openshift.io", "imagestreamimages"),
118+
sets.NewString("imagestreamimports.image.openshift.io", "imagestreamimports"),
119+
sets.NewString("imagestreammappings.image.openshift.io", "imagestreammappings"),
120+
sets.NewString("imagestreams.image.openshift.io", "imagestreams"),
121+
sets.NewString("imagestreamtags.image.openshift.io", "imagestreamtags"),
122+
123+
sets.NewString("clusternetworks.network.openshift.io", "clusternetworks"),
124+
sets.NewString("egressnetworkpolicies.network.openshift.io", "egressnetworkpolicies"),
125+
sets.NewString("hostsubnets.network.openshift.io", "hostsubnets"),
126+
sets.NewString("netnamespaces.network.openshift.io", "netnamespaces"),
127+
128+
sets.NewString("oauthaccesstokens.oauth.openshift.io", "oauthaccesstokens"),
129+
sets.NewString("oauthauthorizetokens.oauth.openshift.io", "oauthauthorizetokens"),
130+
sets.NewString("oauthclientauthorizations.oauth.openshift.io", "oauthclientauthorizations"),
131+
sets.NewString("oauthclients.oauth.openshift.io", "oauthclients"),
132+
133+
sets.NewString("projectrequests.project.openshift.io", "projectrequests"),
134+
sets.NewString("projects.project.openshift.io", "projects"),
135+
136+
sets.NewString("appliedclusterresourcequotas.quota.openshift.io", "appliedclusterresourcequotas"),
137+
sets.NewString("clusterresourcequotas.quota.openshift.io", "clusterresourcequotas"),
138+
139+
sets.NewString("routes.route.openshift.io", "routes"),
140+
141+
sets.NewString("podsecuritypolicyreviews.security.openshift.io", "podsecuritypolicyreviews"),
142+
sets.NewString("podsecuritypolicyselfsubjectreviews.security.openshift.io", "podsecuritypolicyselfsubjectreviews"),
143+
sets.NewString("podsecuritypolicysubjectreviews.security.openshift.io", "podsecuritypolicysubjectreviews"),
144+
145+
sets.NewString("processedtemplates.template.openshift.io", "processedtemplates"),
146+
sets.NewString("templates.template.openshift.io", "templates"),
147+
148+
sets.NewString("groups.user.openshift.io", "groups"),
149+
sets.NewString("identities.user.openshift.io", "identities"),
150+
sets.NewString("useridentitymappings.user.openshift.io", "useridentitymappings"),
151+
sets.NewString("users.user.openshift.io", "users"),
152+
153+
// kubernetes resources:
88154
sets.NewString("horizontalpodautoscalers.autoscaling", "horizontalpodautoscalers.extensions"),
89155
sets.NewString("jobs.batch", "jobs.extensions"),
90156
},

pkg/cmd/admin/registry/registry.go

+1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ func (opts *RegistryOptions) RunCmdRegistry() error {
436436

437437
if opts.Config.Action.ShouldPrint() {
438438
mapper, _ := opts.factory.Object()
439+
opts.cmd.Flag("output-version").Value.Set("extensions/v1beta1,v1")
439440
fn := cmdutil.VersionedPrintObject(opts.factory.PrintObject, opts.cmd, mapper, opts.out)
440441
if err := fn(list); err != nil {
441442
return fmt.Errorf("unable to print object: %v", err)

pkg/cmd/cli/cmd/process.go

+2
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ func RunProcess(f *clientcmd.Factory, in io.Reader, out, errout io.Writer, cmd *
315315
if err != nil {
316316
return err
317317
}
318+
// Prefer the Kubernetes core group for the List over the template.openshift.io
319+
version.Group = kapi.GroupName
318320
p = kubectl.NewVersionedPrinter(p, kapi.Scheme, version)
319321

320322
// use generic output

pkg/cmd/cli/describe/deployments.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ func printDeploymentConfigSpec(kc kclientset.Interface, dc deployapi.DeploymentC
269269
}
270270

271271
// Autoscaling info
272-
printAutoscalingInfo(deployapi.Resource("DeploymentConfig"), dc.Namespace, dc.Name, kc, w)
272+
// FIXME: The CrossVersionObjectReference should specify the Group
273+
printAutoscalingInfo([]unversioned.GroupResource{deployapi.Resource("DeploymentConfig"), deployapi.LegacyResource("DeploymentConfig")}, dc.Namespace, dc.Name, kc, w)
273274

274275
// Triggers
275276
printTriggers(spec.Triggers, w)
@@ -290,16 +291,18 @@ func printDeploymentConfigSpec(kc kclientset.Interface, dc deployapi.DeploymentC
290291
}
291292

292293
// TODO: Move this upstream
293-
func printAutoscalingInfo(res unversioned.GroupResource, namespace, name string, kclient kclientset.Interface, w *tabwriter.Writer) {
294+
func printAutoscalingInfo(res []unversioned.GroupResource, namespace, name string, kclient kclientset.Interface, w *tabwriter.Writer) {
294295
hpaList, err := kclient.Autoscaling().HorizontalPodAutoscalers(namespace).List(kapi.ListOptions{LabelSelector: labels.Everything()})
295296
if err != nil {
296297
return
297298
}
298299

299300
scaledBy := []autoscaling.HorizontalPodAutoscaler{}
300301
for _, hpa := range hpaList.Items {
301-
if hpa.Spec.ScaleTargetRef.Name == name && hpa.Spec.ScaleTargetRef.Kind == res.String() {
302-
scaledBy = append(scaledBy, hpa)
302+
for _, r := range res {
303+
if hpa.Spec.ScaleTargetRef.Name == name && hpa.Spec.ScaleTargetRef.Kind == r.String() {
304+
scaledBy = append(scaledBy, hpa)
305+
}
303306
}
304307
}
305308

pkg/cmd/cli/describe/describer.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
userapi "github.com/openshift/origin/pkg/user/api"
3737
)
3838

39-
func describerMap(c *client.Client, kclient kclientset.Interface, host string) map[unversioned.GroupKind]kctl.Describer {
39+
func describerMap(c *client.Client, kclient kclientset.Interface, host string, withCoreGroup bool) map[unversioned.GroupKind]kctl.Describer {
4040
m := map[unversioned.GroupKind]kctl.Describer{
4141
buildapi.Kind("Build"): &BuildDescriber{c, kclient},
4242
buildapi.Kind("BuildConfig"): &BuildConfigDescriber{c, kclient, host},
@@ -69,6 +69,18 @@ func describerMap(c *client.Client, kclient kclientset.Interface, host string) m
6969
sdnapi.Kind("EgressNetworkPolicy"): &EgressNetworkPolicyDescriber{c},
7070
authorizationapi.Kind("RoleBindingRestriction"): &RoleBindingRestrictionDescriber{c},
7171
}
72+
73+
// Register the legacy ("core") API group for all kinds as well.
74+
if withCoreGroup {
75+
for _, t := range kapi.Scheme.KnownTypes(oapi.SchemeGroupVersion) {
76+
coreKind := oapi.SchemeGroupVersion.WithKind(t.Name())
77+
for g, d := range m {
78+
if g.Kind == coreKind.Kind {
79+
m[oapi.Kind(g.Kind)] = d
80+
}
81+
}
82+
}
83+
}
7284
return m
7385
}
7486

@@ -77,7 +89,7 @@ func DescribableResources() []string {
7789
// Include describable resources in kubernetes
7890
keys := kctl.DescribableResources()
7991

80-
for k := range describerMap(nil, nil, "") {
92+
for k := range describerMap(nil, nil, "", false) {
8193
resource := strings.ToLower(k.Kind)
8294
keys = append(keys, resource)
8395
}
@@ -86,7 +98,7 @@ func DescribableResources() []string {
8698

8799
// DescriberFor returns a describer for a given kind of resource
88100
func DescriberFor(kind unversioned.GroupKind, c *client.Client, kclient kclientset.Interface, host string) (kctl.Describer, bool) {
89-
f, ok := describerMap(c, kclient, host)[kind]
101+
f, ok := describerMap(c, kclient, host, true)[kind]
90102
if ok {
91103
return f, true
92104
}

pkg/cmd/server/bootstrappolicy/infra_sa_policy.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"k8s.io/kubernetes/pkg/util/sets"
1515

1616
authorizationapi "github.com/openshift/origin/pkg/authorization/api"
17+
buildapi "github.com/openshift/origin/pkg/build/api"
1718
)
1819

1920
const (
@@ -158,6 +159,7 @@ func init() {
158159
{
159160
Verbs: sets.NewString("create"),
160161
Resources: sets.NewString("builds/docker", "builds/source", "builds/custom", "builds/jenkinspipeline"),
162+
APIGroups: []string{buildapi.GroupName, buildapi.LegacyGroupName},
161163
},
162164
// BuildController.ImageStreamClient (ControllerClient)
163165
{

0 commit comments

Comments
 (0)