1
- import { CoreV1Api , CustomObjectsApi , KubeConfig } from '@kubernetes/client-node'
1
+ import { CoreV1Api } from '@kubernetes/client-node'
2
2
import retry from 'async-retry'
3
3
import { bootstrapGit , setIdentity } from 'src/common/bootstrap'
4
4
import { prepareEnvironment } from 'src/common/cli'
5
5
import { encrypt } from 'src/common/crypt'
6
6
import { terminal } from 'src/common/debug'
7
7
import { env , isCi } from 'src/common/envalid'
8
8
import { hfValues } from 'src/common/hf'
9
- import { createGenericSecret , waitTillGitRepoAvailable } from 'src/common/k8s'
9
+ import { createGenericSecret , k8s , waitTillGitRepoAvailable } from 'src/common/k8s'
10
10
import { getFilename } from 'src/common/utils'
11
11
import { getRepo } from 'src/common/values'
12
12
import { HelmArguments , getParsedArgs , setParsedArgs } from 'src/common/yargs'
@@ -128,12 +128,9 @@ export async function retryCheckingForPipelineRun() {
128
128
129
129
export async function retryIsOAuth2ProxyRunning ( ) {
130
130
const d = terminal ( `cmd:${ cmdName } :isOAuth2ProxyRunning` )
131
- const kc = new KubeConfig ( )
132
- kc . loadFromDefault ( )
133
- const coreV1Api = kc . makeApiClient ( CoreV1Api )
134
131
await retry (
135
132
async ( ) => {
136
- await isOAuth2ProxyAvailable ( coreV1Api )
133
+ await isOAuth2ProxyAvailable ( k8s . core ( ) )
137
134
} ,
138
135
{ retries : env . RETRIES , randomize : env . RANDOM , minTimeout : env . MIN_TIMEOUT , factor : env . FACTOR } ,
139
136
) . catch ( ( e ) => {
@@ -142,10 +139,10 @@ export async function retryIsOAuth2ProxyRunning() {
142
139
} )
143
140
}
144
141
145
- export async function isOAuth2ProxyAvailable ( k8s : CoreV1Api ) : Promise < void > {
142
+ export async function isOAuth2ProxyAvailable ( coreV1Api : CoreV1Api ) : Promise < void > {
146
143
const d = terminal ( `cmd:${ cmdName } :isOAuth2ProxyRunning` )
147
144
d . info ( 'Checking if OAuth2Proxy is available, waiting...' )
148
- const { body : oauth2ProxyEndpoint } = await k8s . readNamespacedEndpoints ( 'oauth2-proxy' , 'istio-system' )
145
+ const { body : oauth2ProxyEndpoint } = await coreV1Api . readNamespacedEndpoints ( 'oauth2-proxy' , 'istio-system' )
149
146
if ( ! oauth2ProxyEndpoint ) {
150
147
throw new Error ( 'OAuth2Proxy endpoint not found, waiting...' )
151
148
}
@@ -163,16 +160,10 @@ export async function isOAuth2ProxyAvailable(k8s: CoreV1Api): Promise<void> {
163
160
164
161
export async function checkIfPipelineRunExists ( ) : Promise < void > {
165
162
const d = terminal ( `cmd:${ cmdName } :pipelineRun` )
166
- const kc = new KubeConfig ( )
167
- kc . loadFromDefault ( )
168
- const customObjectsApi = kc . makeApiClient ( CustomObjectsApi )
169
163
170
- const response = await customObjectsApi . listNamespacedCustomObject (
171
- 'tekton.dev' ,
172
- 'v1beta1' ,
173
- 'otomi-pipelines' ,
174
- 'pipelineruns' ,
175
- )
164
+ const response = await k8s
165
+ . custom ( )
166
+ . listNamespacedCustomObject ( 'tekton.dev' , 'v1beta1' , 'otomi-pipelines' , 'pipelineruns' )
176
167
177
168
const pipelineRuns = ( response . body as { items : any [ ] } ) . items
178
169
if ( pipelineRuns . length === 0 ) {
@@ -186,10 +177,7 @@ export async function checkIfPipelineRunExists(): Promise<void> {
186
177
187
178
async function createCredentialsSecret ( secretName : string , username : string , password : string ) : Promise < void > {
188
179
const secretData = { username, password }
189
- const kc = new KubeConfig ( )
190
- kc . loadFromDefault ( )
191
- const coreV1Api = kc . makeApiClient ( CoreV1Api )
192
- await createGenericSecret ( coreV1Api , secretName , 'keycloak' , secretData )
180
+ await createGenericSecret ( k8s . core ( ) , secretName , 'keycloak' , secretData )
193
181
}
194
182
195
183
export const printWelcomeMessage = async ( ) : Promise < void > => {
0 commit comments