-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replication Controllers (new resource view) (#7154)
* New resource view: ReplicationController -- scaffolding files Signed-off-by: Roman <ixrock@gmail.com> * fix: inappropriate names after copy-pasting Signed-off-by: Roman <ixrock@gmail.com> * update replication controller api types/spec, fix menu title Signed-off-by: Roman <ixrock@gmail.com> * items list + details list views (added contents from replication controllers), lint fixes Signed-off-by: Roman <ixrock@gmail.com> * allow to scale replication controllers Signed-off-by: Roman <ixrock@gmail.com> * switched for scaling replicas with `Slider` component instead of `Buttons+Input` Signed-off-by: Roman <ixrock@gmail.com> --------- Signed-off-by: Roman <ixrock@gmail.com>
- Loading branch information
Showing
17 changed files
with
610 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...luster/workloads/replicationcontrollers/navigate-to-replication-controllers.injectable.ts
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,20 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import replicationControllersRouteInjectable from "./replicationcontrollers-route.injectable"; | ||
import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token"; | ||
|
||
const navigateToReplicationControllersInjectable = getInjectable({ | ||
id: "navigate-to-replicationcontrollers", | ||
|
||
instantiate: (di) => { | ||
const navigateToRoute = di.inject(navigateToRouteInjectionToken); | ||
const route = di.inject(replicationControllersRouteInjectable); | ||
|
||
return () => navigateToRoute(route); | ||
}, | ||
}); | ||
|
||
export default navigateToReplicationControllersInjectable; |
24 changes: 24 additions & 0 deletions
24
...outes/cluster/workloads/replicationcontrollers/replicationcontrollers-route.injectable.ts
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,24 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token"; | ||
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token"; | ||
|
||
const replicationControllersRouteInjectable = getInjectable({ | ||
id: "replicationcontrollers-route", | ||
|
||
instantiate: (di) => ({ | ||
path: "/replicationcontrollers", | ||
clusterFrame: true, | ||
isEnabled: di.inject(shouldShowResourceInjectionToken, { | ||
apiName: "replicationcontrollers", | ||
group: "", // core | ||
}), | ||
}), | ||
|
||
injectionToken: frontEndRouteInjectionToken, | ||
}); | ||
|
||
export default replicationControllersRouteInjectable; |
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
23 changes: 23 additions & 0 deletions
23
packages/core/src/common/k8s-api/endpoints/replication-controller.api.injectable.ts
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,23 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token"; | ||
import loggerInjectable from "../../logger.injectable"; | ||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable"; | ||
import { ReplicationControllerApi } from "./replication-controller.api"; | ||
|
||
const replicationControllerApiInjectable = getInjectable({ | ||
id: "replication-controller-api", | ||
instantiate: (di) => { | ||
return new ReplicationControllerApi({ | ||
logger: di.inject(loggerInjectable), | ||
maybeKubeApi: di.inject(maybeKubeApiInjectable), | ||
}); | ||
}, | ||
|
||
injectionToken: kubeApiInjectionToken, | ||
}); | ||
|
||
export default replicationControllerApiInjectable; |
149 changes: 149 additions & 0 deletions
149
packages/core/src/common/k8s-api/endpoints/replication-controller.api.ts
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,149 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
|
||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; | ||
import { KubeApi } from "../kube-api"; | ||
import type { | ||
BaseKubeObjectCondition, KubeObjectMetadata, | ||
KubeObjectStatus, | ||
NamespaceScopedMetadata, | ||
} from "../kube-object"; | ||
import { KubeObject } from "../kube-object"; | ||
import type { PodTemplateSpec } from "./types"; | ||
|
||
export class ReplicationControllerApi extends KubeApi<ReplicationController> { | ||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { | ||
super(deps, { | ||
...opts ?? {}, | ||
objectConstructor: ReplicationController, | ||
}); | ||
} | ||
|
||
protected getScaleApiUrl(params: { namespace: string; name: string }) { | ||
return `${this.formatUrlForNotListing(params)}/scale`; | ||
} | ||
|
||
getScale(params: { namespace: string; name: string }): Promise<Scale> { | ||
return this.request.get(this.getScaleApiUrl(params)); | ||
} | ||
|
||
scale(params: { namespace: string; name: string }, replicas: number): Promise<Scale> { | ||
return this.request.patch(this.getScaleApiUrl(params), { | ||
data: { | ||
metadata: params, | ||
spec: { | ||
replicas, | ||
}, | ||
}, | ||
}, { | ||
headers: { | ||
"content-type": "application/strategic-merge-patch+json", | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export interface Scale { | ||
apiVersion: "autoscaling/v1"; | ||
kind: "Scale"; | ||
metadata: KubeObjectMetadata; | ||
spec: { | ||
replicas: number; | ||
}; | ||
status: { | ||
replicas: number; | ||
selector: string; | ||
}; | ||
} | ||
|
||
export interface ReplicationControllerSpec { | ||
/** | ||
* Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. | ||
* Defaults to 0 (pod will be considered available as soon as it is ready) | ||
*/ | ||
minReadySeconds?: number; | ||
/** | ||
* Replicas is the number of desired replicas. This is a pointer to distinguish between explicit zero and unspecified. | ||
* Defaults to 1. More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller | ||
*/ | ||
replicas?: number; | ||
/** | ||
* Selector is a label query over pods that should match the Replicas count. If Selector is empty, it is defaulted to the labels present on the Pod template. | ||
* Label keys and values that must match in order to be controlled by this replication controller, if empty defaulted to labels on Pod template. | ||
* More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors | ||
*/ | ||
selector?: Record<string, string>; | ||
/** | ||
* Template is the object that describes the pod that will be created if insufficient replicas are detected. This takes precedence over a TemplateRef. | ||
* More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template | ||
*/ | ||
template: PodTemplateSpec; | ||
} | ||
|
||
export interface ReplicationControllerStatus extends KubeObjectStatus { | ||
/** | ||
* The number of available replicas (ready for at least minReadySeconds) for this replication controller. | ||
*/ | ||
availableReplicas: number; | ||
/** | ||
* The number of pods that have labels matching the labels of the pod template of the replication controller. | ||
*/ | ||
fullyLabeledReplicas: number; | ||
/** | ||
* ObservedGeneration reflects the generation of the most recently observed replication controller. | ||
*/ | ||
observedGeneration: number; | ||
/** | ||
* The number of ready replicas for this replication controller. | ||
*/ | ||
readyReplicas: number; | ||
/** | ||
* Replicas is the most recently observed number of replicas. | ||
* More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller | ||
*/ | ||
replicas: number; | ||
} | ||
|
||
export class ReplicationController extends KubeObject< | ||
NamespaceScopedMetadata, | ||
ReplicationControllerStatus, | ||
ReplicationControllerSpec | ||
> { | ||
static kind = "ReplicationController"; | ||
static namespaced = true; | ||
static apiBase = "/api/v1/replicationcontrollers"; | ||
|
||
getMinReadySeconds(): number { | ||
return this.spec?.minReadySeconds ?? 0; | ||
} | ||
|
||
getGeneration() { | ||
return this.status?.observedGeneration; | ||
} | ||
|
||
getSelectorLabels(): string[] { | ||
return KubeObject.stringifyLabels(this.spec.selector); | ||
} | ||
|
||
getReplicas(): number | undefined { | ||
return this.status?.replicas; | ||
} | ||
|
||
getDesiredReplicas(): number { | ||
return this.spec?.replicas ?? 0; | ||
} | ||
|
||
getAvailableReplicas(): number | undefined { | ||
return this.status?.availableReplicas; | ||
} | ||
|
||
getLabeledReplicas(): number | undefined { | ||
return this.status?.fullyLabeledReplicas; | ||
} | ||
|
||
getConditions(): BaseKubeObjectCondition[] { | ||
return this.status?.conditions ?? []; | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
packages/core/src/renderer/components/+workloads-replicationcontrollers/index.ts
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 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
|
||
export * from "./replicationcontrollers"; | ||
export * from "./replicationcontroller-details"; |
24 changes: 24 additions & 0 deletions
24
...s/+workloads-replicationcontrollers/replication-controllers-route-component.injectable.ts
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,24 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import { ReplicationControllers } from "./replicationcontrollers"; | ||
import { | ||
routeSpecificComponentInjectionToken, | ||
} from "../../routes/route-specific-component-injection-token"; | ||
import replicationControllersRouteInjectable | ||
from "../../../common/front-end-routing/routes/cluster/workloads/replicationcontrollers/replicationcontrollers-route.injectable"; | ||
|
||
const replicationControllersRouteComponentInjectable = getInjectable({ | ||
id: "replicationcontroller-route-component", | ||
|
||
instantiate: (di) => ({ | ||
route: di.inject(replicationControllersRouteInjectable), | ||
Component: ReplicationControllers, | ||
}), | ||
|
||
injectionToken: routeSpecificComponentInjectionToken, | ||
}); | ||
|
||
export default replicationControllersRouteComponentInjectable; |
16 changes: 16 additions & 0 deletions
16
...er/components/+workloads-replicationcontrollers/replicationcontroller-details.module.scss
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,16 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
|
||
.ReplicationControllerDetails { | ||
.replicas { | ||
display: flex; | ||
gap: calc(var(--margin) * 2); | ||
align-items: center; | ||
|
||
> * { | ||
flex-shrink: 0; | ||
} | ||
} | ||
} |
Oops, something went wrong.