-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add service and services fluent interface implementation (#1303)
Signed-off-by: Nathan Klick <[email protected]> Co-authored-by: Jeromy Cannon <[email protected]>
- Loading branch information
1 parent
013caa5
commit 8ef6998
Showing
18 changed files
with
216 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import {type ObjectMeta} from '../object_meta.js'; | ||
import {type NamespaceName} from '../namespace_name.js'; | ||
|
||
export class K8ClientObjectMeta implements ObjectMeta { | ||
constructor( | ||
public readonly namespace: NamespaceName, | ||
public readonly name: string, | ||
public readonly labels?: {[key: string]: string}, | ||
public readonly annotations?: {[key: string]: string}, | ||
public readonly uid?: string, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import {type Service} from '../service.js'; | ||
import {type ObjectMeta} from '../object_meta.js'; | ||
import {type ServiceSpec} from '../service_spec.js'; | ||
import {type ServiceStatus} from '../service_status.js'; | ||
|
||
export class K8ClientService implements Service { | ||
public constructor( | ||
public readonly metadata: ObjectMeta, | ||
public readonly spec: ServiceSpec, | ||
public readonly status?: ServiceStatus, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import {type Services} from '../services.js'; | ||
import {type NamespaceName} from '../namespace_name.js'; | ||
import {type CoreV1Api, type V1Service} from '@kubernetes/client-node'; | ||
import {K8ClientBase} from './k8_client_base.js'; | ||
import {type Service} from '../service.js'; | ||
import {KubeApiResponse} from '../kube_api_response.js'; | ||
import {ResourceOperation} from '../resource_operation.js'; | ||
import {ResourceType} from '../resource_type.js'; | ||
import {K8ClientService} from './k8_client_service.js'; | ||
import {type ServiceSpec} from '../service_spec.js'; | ||
import {type ServiceStatus} from '../service_status.js'; | ||
|
||
export class K8ClientServices extends K8ClientBase implements Services { | ||
public constructor(private readonly kubeClient: CoreV1Api) { | ||
super(); | ||
} | ||
|
||
public async list(namespace: NamespaceName, labels?: string[]): Promise<Service[]> { | ||
const labelSelector = labels ? labels.join(',') : undefined; | ||
const serviceList = await this.kubeClient.listNamespacedService( | ||
namespace.name, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
labelSelector, | ||
); | ||
KubeApiResponse.check(serviceList.response, ResourceOperation.LIST, ResourceType.SERVICE, namespace, ''); | ||
return serviceList.body.items.map((svc: V1Service) => { | ||
return this.wrapService(namespace, svc); | ||
}); | ||
} | ||
|
||
public async read(namespace: NamespaceName, name: string): Promise<Service> { | ||
const svc = await this.readV1Service(namespace, name); | ||
|
||
if (!svc) { | ||
return null; | ||
} | ||
|
||
return this.wrapService(namespace, svc); | ||
} | ||
|
||
private async readV1Service(namespace: NamespaceName, name: string): Promise<V1Service> { | ||
const {response, body} = await this.kubeClient.readNamespacedService(name, namespace.name); | ||
KubeApiResponse.check(response, ResourceOperation.READ, ResourceType.SERVICE, namespace, name); | ||
return body as V1Service; | ||
} | ||
|
||
private wrapService(namespace: NamespaceName, svc: V1Service): Service { | ||
return new K8ClientService(this.wrapObjectMeta(svc.metadata), svc.spec as ServiceSpec, svc.status as ServiceStatus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
export interface LoadBalancerIngress { | ||
readonly hostname?: string; | ||
readonly ip?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import {type LoadBalancerIngress} from './load_balancer_ingress.js'; | ||
|
||
export interface LoadBalancerStatus { | ||
readonly ingress?: LoadBalancerIngress[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import {type NamespaceName} from './namespace_name.js'; | ||
|
||
export interface ObjectMeta { | ||
readonly namespace?: NamespaceName; | ||
readonly name: string; | ||
readonly labels?: {[key: string]: string}; | ||
readonly annotations?: {[key: string]: string}; | ||
readonly uid?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ export enum ResourceOperation { | |
UPDATE = 'update', | ||
DELETE = 'delete', | ||
REPLACE = 'replace', | ||
LIST = 'list', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import {type ObjectMeta} from './object_meta.js'; | ||
import {type ServiceSpec} from './service_spec.js'; | ||
import {type ServiceStatus} from './service_status.js'; | ||
|
||
export interface Service { | ||
readonly metadata?: ObjectMeta; | ||
readonly spec?: ServiceSpec; | ||
readonly status?: ServiceStatus; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
export interface ServicePort { | ||
readonly name?: string; | ||
readonly port: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import {type ServicePort} from './service_port.js'; | ||
|
||
export interface ServiceSpec { | ||
readonly clusterIP?: string; | ||
readonly ports?: ServicePort[]; | ||
readonly selector?: {[key: string]: string}; | ||
} |
Oops, something went wrong.