fabric8io / kubernetes-client

Java client for Kubernetes & OpenShift
http://fabric8.io
Apache License 2.0
3.39k stars 1.46k forks source link

Unable to create Openshift Route | the API version in the data (v1) does not match the expected API version (route.openshift.io/v1) #1947

Closed cedar715 closed 4 years ago

cedar715 commented 4 years ago

We upgraded Fabric8 from 4.1.1 to 4.7.0. All the manifests are getting applied correctly except for the Route:

11:39:19  Caused by: io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: PUT at: https://192.168.64.1/apis/route.openshift.io/v1/namespaces/openbanking-observability/routes/grafana. Message: the API version in the data (v1) does not match the expected API version (route.openshift.io/v1). Received status: Status(apiVersion=v1, code=400, details=null, kind=Status, message=the API version in the data (v1) does not match the expected API version (route.openshift.io/v1), metadata=ListMeta(_continue=
11:39:19  null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=BadRequest, status=Failure, additionalProperties={}).
11:39:19    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.requestFailure(OperationSupport.java:568)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.assertResponseCode(OperationSupport.java:507)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:471)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:430)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleReplace(OperationSupport.java:289)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleReplace(OperationSupport.java:269)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.handleReplace(BaseOperation.java:812)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation.lambda$replace$1(HasMetadataOperation.java:86)
11:39:19    at io.fabric8.openshift.api.model.DoneableRoute.done(DoneableRoute.java:27)
11:39:19    at io.fabric8.openshift.api.model.DoneableRoute.done(DoneableRoute.java:6)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation.replace(HasMetadataOperation.java:92)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation.replace(HasMetadataOperation.java:36)
11:39:19    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.createOrReplace(BaseOperation.java:383)
11:39:19    at RouteOperationsImpl1_groovyProxy.createOrReplace(Unknown Source)
rohanKanojia commented 4 years ago

@cedar715 : Could you please share code from which you're trying to create route? And what does your current route look like? Looks like a case of mis-matching apiVersions.

cedar715 commented 4 years ago
        final RouteList routes = openShiftClient.routes().inNamespace(namespace).list()

        final List<Route> routeList = routes.getItems()
        final Route existingRoute = routeList.find {
            it.metadata?.name == routeName
        }

        final Route enrichedRoute = enrichTLSConfig(routeFolderPath, route)
        ScalableResource<Route, DoneableRoute> routeOpr = openShiftClient.routes().inNamespace(namespace).withName(routeName) as ScalableResource

        if (existingRoute) {
            final Boolean isDeleted = routeOpr.delete()
            log.info("Deleted route $routeName? :: $isDeleted")
            if (!isDeleted) {
                log.error("Route exists with the name $routeName and could NOT be deleted, terminating!")
                throw new KubeClientException("Route exists with the name $routeName and could NOT be deleted!");
            }
        }
        Route result = routeOpr.createOrReplace(enrichedRoute) as Route
        log.info("Created route: $route")

We don't specify apiVersion in the manifests; its delegated to Fabric8 to determine the apt version based on the cluster version.

cedar715 commented 4 years ago
final VersionInfo versionInfo = namespaceOcpClient.version
final String apiVersionToUse = openshiftVersion?.startsWith('3.7') ? 'v1' : 'route.openshift.io/v1'

Got resolved when we explicitly set the version.