Bug 2057054 - SDK: k8s methods resolves into Response instead of the Resource
Summary: SDK: k8s methods resolves into Response instead of the Resource
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Management Console
Version: 4.11
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ---
: 4.11.0
Assignee: Andrew Ballantyne
QA Contact: Xiyun Zhao
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-02-22 16:15 UTC by Gilad Lekner
Modified: 2022-08-10 10:51 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-08-10 10:50:45 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github openshift console pull 11103 0 None open Bug 2057054: Improves K8s Utils Return Type 2022-02-24 22:09:21 UTC
Red Hat Product Errata RHSA-2022:5069 0 None None None 2022-08-10 10:51:02 UTC

Description Gilad Lekner 2022-02-22 16:15:36 UTC
Description of problem:
k8s methods resolves into Response instead of the Resource

Steps to Reproduce:
1.run k8sCreate and see the returned type is a Response instead of the Resource

Actual results:
Returned a Response type

Expected results:
Returned a Resource type

Additional info:
example with VirtualMachineModel:

k8sCreate<V1VirtualMachine>(options: OptionsCreate<V1VirtualMachine>): Promise<Response>

The promise should return a VirtualMachine.

Comment 1 Andrew Ballantyne 2022-02-24 15:58:58 UTC
Initial investigation:

- This is something that HAC-Core introduced when setting up a more dynamic layer to the k8s calls
- The issue is with how the new types are defined
- OpenShift Console code doesn't use this new code, it still uses old code
- HAC-Core exported the new functions as the old names out of the SDK API -- so this change here is where things broke (and was otherwise untested since no one used the SDK yet)


The bug is in the type definition.

Comment 4 Xiyun Zhao 2022-03-17 02:16:54 UTC
This bug has been verified on payload 4.11.0-0.nightly-2022-03-14-113722, with the newest OCP code

Verification Step:
1. Checkout OpenShift Console to local
2. Open up VS Code(or other IDE) to OpenShift console
   2.1 [In the CLI/Terminal] In the root of the repo, run ./clean.sh & then ./build.sh
   2.2 [In the CLI/Terminal] Go to dynamic-demo-plugin folder in the root of the repo, and run the command as below:
       rm -rf node_modules/ && yarn install && yarn build
   2.3 Verify if upon step is running successfully without any Type error like below shown
       ERROR in ./consolenew/dynamic-demo-plugin/src/components/k8sConsumer/K8sAPIConsumer.tsx 
       95:12-59
       [tsl] ERROR in ./consolenew/dynamic-demo-plugin/src/components/k8sConsumer/K8sAPIConsumer.tsx(95,13)
            TS2345: Argument of type '{ model: K8sModel; queryParams: { ns: string; }; }' is not assignable to parameter of type 'OptionsList'.
              Property 'requestInit' is missing in type '{ model: K8sModel; queryParams: { ns: string; }; }' but required in type 'OptionsList'.

       ERROR in ./consolenew/dynamic-demo-plugin/src/components/k8sConsumer/K8sAPIConsumer.tsx
       97:21-29
       [tsl] ERROR in ./consolenew/dynamic-demo-plugin/src/components/k8sConsumer/K8sAPIConsumer.tsx(97,22)
             TS2345: Argument of type 'K8sResourceCommon[] | (K8sResourceCommon & { items: K8sResourceCommon[]; })' is not assignable to parameter of type 'SetStateAction<K8sResourceCommon[]>'.
         Type 'K8sResourceCommon & { items: K8sResourceCommon[]; }' is not assignable to type 'SetStateAction<K8sResourceCommon[]>'.
           Type 'K8sResourceCommon & { items: K8sResourceCommon[]; }' is not assignable to type '(prevState: K8sResourceCommon[]) => K8sResourceCommon[]'.       
             Type 'K8sResourceCommon & { items: K8sResourceCommon[]; }' provides no match for the signature '(prevState: K8sResourceCommon[]): K8sResourceCommon[]'.

       ERROR in ./consolenew/dynamic-demo-plugin/src/components/k8sConsumer/K8sAPIConsumer.tsx
       107:14-60
       [tsl] ERROR in ./consolenew/dynamic-demo-plugin/src/components/k8sConsumer/K8sAPIConsumer.tsx(107,15)
             TS2345: Argument of type '{ model: K8sModel; resource: { apiVersion: string; kind: string; metadata: { name: string; namespace: string; labels: { app: string; }; }; spec: { selector: { matchLabels: { app: string; }; }; 
       replicas: number; template: { ...; }; }; }; }' is not assignable to parameter of type 'OptionsDelete<{ apiVersion: string; kind: string; metadata: { name: string; namespace: string; labels: { app: string; }; }; spec: { 
       selector: { matchLabels: { app: string; }; }; replicas: number; template: { metadata: { labels: { ...; }; }; spec: { ...; }; }; }; }>'.
         Type '{ model: K8sModel; resource: { apiVersion: string; kind: string; metadata: { name: string; namespace: string; labels: { app: string; }; }; spec: { selector: { matchLabels: { app: string; }; }; replicas: number; 
       template: { ...; }; }; }; }' is missing the following properties from type '{ model: K8sModel; resource: { apiVersion: string; kind: string; metadata: { name: string; namespace: string; labels: { app: string; }; }; spec: { 
        selector: { matchLabels: { app: string; }; }; replicas: number; template: { ...; }; }; }; requestInit: RequestInit; json: Record<...>; }': requestInit, json       
   2.4 [In VS Code] Navigate to a test file dynamic-demo-plugin/src/components/k8sConsumer/K8sAPIConsumer.tsx
   2.5 [In VS Code] Hover over the <response> and inspect the type of response on IDE
         const k8sGetClick = () => {
           k8sGet({ model: k8sModel, name: 'sampleapp', ns: 'default' })
             .then((response) => {
   2.6 Verify if the response is point to K8sResourceCommon, but not Response
   2.7 Import a new function like k8sCreateResource(); on the file, hover over the call to the function and inspect the return value
   2.8 Verify if the type of K8sResourceCommon is returned from that function
3. Following below command to build a dynamic plugin(Note: Following the Steps to run the command on different terminal)
step 0: Login OCP by using CLI
        Terminal 1: under path ./console/
step 1: $ source ./contrib/oc-environment.sh
step 8: $./bin/bridge -plugins console-demo-plugin=http://localhost:9001

        Terminal 2: under path ./console/frontend/
step 2: $ yarn install
step 3: $ yarn build
step 7: $ yarn dev

        Terminal 3: under path .console/dynamic-demo-plugin
step 4: $ yarn install
step 5: $ yarn run build
step 6: $ yarn http-server
4. Verify if the OKD page is load normally, and the function of plugin can be shown and worked on page  

Result: 
2.3. No issue return, dynamic-demo-plugin is built without error
       [20] ./node_modules/monaco-editor/esm/vs/base/common/arrays.js 7.5 KiB {0} [built]
       [22] ./node_modules/monaco-editor/esm/vs/editor/common/diff/diffComputer.js 21 KiB {0} [built]
       [34] ./node_modules/monaco-editor/esm/vs/editor/editor.worker.js 1.07 KiB {0} [built]
        + 23 hidden modules
       Done in 438.40s. 
2.6. The Type of response is point to K8sResourceCommon
       (parameter) response: K8sResourceCommon
2.8.  The Type of K8sResourceCommon is return as below shown
       (alias) k8sCreateResource<K8sResourceCommon>(options: OptionsCreate<K8sResourceCommon>): Promise<K8sResourceCommon>
       import k8sCreateResource
4. The OKD page is loading normally without any error, the component of dynamic-demo-plugin is shown well

Comment 6 errata-xmlrpc 2022-08-10 10:50:45 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: OpenShift Container Platform 4.11.0 bug fix and security update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:5069


Note You need to log in before you can comment on or make changes to this bug.