Skip to content

Commit

Permalink
update tests for oapi removal
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Jan 29, 2019
1 parent fd57997 commit 53288d4
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 1,005 deletions.
1 change: 0 additions & 1 deletion pkg/api/legacy/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
)

var (
RESTPrefix = "/oapi"
GroupName = ""
GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
InternalGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}
Expand Down
3 changes: 0 additions & 3 deletions pkg/build/apiserver/registry/buildconfig/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/openshift/api/build"
buildv1 "github.com/openshift/api/build/v1"
buildclienttyped "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1"
"github.com/openshift/origin/pkg/api/legacy"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
buildv1helpers "github.com/openshift/origin/pkg/build/apis/build/v1"
"github.com/openshift/origin/pkg/build/client"
Expand All @@ -35,8 +34,6 @@ var (
)

func init() {
// webhooks need to return legacy build serialization when hit via oapi
legacy.InstallInternalLegacyBuild(webhookEncodingScheme)
// TODO eventually we shouldn't deal in internal versions, but for now decode into one.
utilruntime.Must(buildv1helpers.Install(webhookEncodingScheme))
webhookEncodingCodecFactory = serializer.NewCodecFactory(webhookEncodingScheme)
Expand Down
52 changes: 0 additions & 52 deletions pkg/cmd/openshift-apiserver/openshiftapiserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"time"

"github.com/emicklei/go-restful-swagger12"
"github.com/golang/glog"

"k8s.io/apiserver/pkg/admission"
Expand All @@ -25,7 +24,6 @@ import (
openshiftcontrolplanev1 "github.com/openshift/api/openshiftcontrolplane/v1"
"github.com/openshift/library-go/pkg/config/helpers"
"github.com/openshift/origin/pkg/admission/namespaceconditions"
"github.com/openshift/origin/pkg/api/legacy"
originadmission "github.com/openshift/origin/pkg/apiserver/admission"
"github.com/openshift/origin/pkg/cmd/openshift-apiserver/openshiftapiserver/configprocessing"
configlatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest"
Expand Down Expand Up @@ -101,10 +99,8 @@ func NewOpenshiftAPIConfig(config *openshiftcontrolplanev1.OpenShiftAPIServerCon
genericConfig.AuditPolicyChecker = policyChecker
genericConfig.ExternalAddress = "apiserver.openshift-apiserver.svc"
genericConfig.BuildHandlerChainFunc = OpenshiftHandlerChain
genericConfig.LegacyAPIGroupPrefixes = configprocessing.LegacyAPIGroupPrefixes
genericConfig.RequestInfoResolver = configprocessing.OpenshiftRequestInfoResolver()
genericConfig.OpenAPIConfig = configprocessing.DefaultOpenAPIConfig(nil)
genericConfig.SwaggerConfig = defaultSwaggerConfig()
genericConfig.RESTOptionsGetter = restOptsGetter
// previously overwritten. I don't know why
genericConfig.RequestTimeout = time.Duration(60) * time.Second
Expand Down Expand Up @@ -259,54 +255,6 @@ func NewOpenshiftAPIConfig(config *openshiftcontrolplanev1.OpenShiftAPIServerCon
return ret, ret.ExtraConfig.Validate()
}

var apiInfo = map[string]swagger.Info{
legacy.RESTPrefix + "/" + legacy.GroupVersion.Version: {
Title: "OpenShift v1 REST API",
Description: `The OpenShift API exposes operations for managing an enterprise Kubernetes cluster, including security and user management, application deployments, image and source builds, HTTP(s) routing, and project management.`,
},
}

// customizeSwaggerDefinition applies selective patches to the swagger API docs
// TODO: move most of these upstream or to go-restful
func customizeSwaggerDefinition(apiList *swagger.ApiDeclarationList) {
for path, info := range apiInfo {
if dec, ok := apiList.At(path); ok {
if len(info.Title) > 0 {
dec.Info.Title = info.Title
}
if len(info.Description) > 0 {
dec.Info.Description = info.Description
}
apiList.Put(path, dec)
} else {
glog.Warningf("No API exists for predefined swagger description %s", path)
}
}
for _, version := range []string{legacy.RESTPrefix + "/" + legacy.GroupVersion.Version} {
apiDeclaration, _ := apiList.At(version)
models := &apiDeclaration.Models

model, _ := models.At("runtime.RawExtension")
model.Required = []string{}
model.Properties = swagger.ModelPropertyList{}
model.Description = "this may be any JSON object with a 'kind' and 'apiVersion' field; and is preserved unmodified by processing"
models.Put("runtime.RawExtension", model)

model, _ = models.At("patch.Object")
model.Description = "represents an object patch, which may be any of: JSON patch (RFC 6902), JSON merge patch (RFC 7396), or the Kubernetes strategic merge patch"
models.Put("patch.Object", model)

apiDeclaration.Models = *models
apiList.Put(version, apiDeclaration)
}
}

func defaultSwaggerConfig() *swagger.Config {
ret := genericapiserver.DefaultSwaggerConfig()
ret.PostBuildHandler = customizeSwaggerDefinition
return ret
}

func OpenshiftHandlerChain(apiHandler http.Handler, genericConfig *genericapiserver.Config) http.Handler {
// this is the normal kube handler chain
handler := genericapiserver.DefaultBuildHandlerChain(apiHandler, genericConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ func DefaultOpenAPIConfig(oauthMetadata *oauthutil.OauthAuthorizationServerMetad
op := r.Operation
path := r.Path
// DEPRECATED: These endpoints are going to be removed in 1.8 or 1.9 release.
if strings.HasPrefix(path, "/oapi/v1/namespaces/{namespace}/processedtemplates") {
op = "createNamespacedProcessedTemplate"
} else if strings.HasPrefix(path, "/apis/template.openshift.io/v1/namespaces/{namespace}/processedtemplates") {
if strings.HasPrefix(path, "/apis/template.openshift.io/v1/namespaces/{namespace}/processedtemplates") {
op = "createNamespacedProcessedTemplateV1"
} else if strings.HasPrefix(path, "/oapi/v1/processedtemplates") {
op = "createProcessedTemplateForAllNamespacesV1"
} else if strings.HasPrefix(path, "/apis/template.openshift.io/v1/processedtemplates") {
op = "createProcessedTemplateForAllNamespaces"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package configprocessing

import (
"github.com/openshift/origin/pkg/api/legacy"
oauthorizer "github.com/openshift/origin/pkg/authorization/authorizer"
"k8s.io/apimachinery/pkg/util/sets"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
genericapiserver "k8s.io/apiserver/pkg/server"
)

var LegacyAPIGroupPrefixes = sets.NewString(genericapiserver.DefaultLegacyAPIPrefix, legacy.RESTPrefix)

func OpenshiftRequestInfoResolver() apirequest.RequestInfoResolver {
// Default API request info factory
requestInfoFactory := &apirequest.RequestInfoFactory{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"

kubecontrolplanev1 "github.com/openshift/api/kubecontrolplane/v1"
"github.com/openshift/origin/pkg/api/legacy"
)

var (
Expand Down Expand Up @@ -262,7 +261,7 @@ func TestVersionSkewFilterSkippedOnNonAPIRequest(t *testing.T) {

func testHandlerChain(handler http.Handler) http.Handler {
kgenericconfig := apiserver.NewConfig(legacyscheme.Codecs)
kgenericconfig.LegacyAPIGroupPrefixes = sets.NewString(apiserver.DefaultLegacyAPIPrefix, legacy.RESTPrefix)
kgenericconfig.LegacyAPIGroupPrefixes = sets.NewString(apiserver.DefaultLegacyAPIPrefix)

handler = apifilters.WithRequestInfo(handler, apiserver.NewRequestInfoResolver(kgenericconfig))
return handler
Expand Down
Loading

0 comments on commit 53288d4

Please sign in to comment.