Skip to content

Commit

Permalink
Merge pull request #2118 from headlamp-k8s/deployment-fixes
Browse files Browse the repository at this point in the history
Deployment fixes
  • Loading branch information
joaquimrocha authored Jul 11, 2024
2 parents ab5f2c8 + 879b031 commit 45a0dc5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/App/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ const mdiIcons = {
restart: {
body: '<path fill="currentColor" d="M12 4c2.1 0 4.1.8 5.6 2.3c3.1 3.1 3.1 8.2 0 11.3c-1.8 1.9-4.3 2.6-6.7 2.3l.5-2c1.7.2 3.5-.4 4.8-1.7c2.3-2.3 2.3-6.1 0-8.5C15.1 6.6 13.5 6 12 6v4.6l-5-5l5-5V4M6.3 17.6C3.7 15 3.3 11 5.1 7.9l1.5 1.5c-1.1 2.2-.7 5 1.2 6.8c.5.5 1.1.9 1.8 1.2l-.6 2c-1-.4-1.9-1-2.7-1.8Z"/>',
},
'content-copy': {
body: '<path fill="currentColor" d="M19 21H8V7h11m0-2H8a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2m-3-4H4a2 2 0 0 0-2 2v14h2V3h12V1Z"/>',
},
minus: {
body: '<path fill="currentColor" d="M19 13H5v-2h14v2Z"/>',
},
Expand Down Expand Up @@ -311,6 +308,9 @@ const mdiIcons = {
star: {
body: '<path fill="currentColor" d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.62L12 2L9.19 8.62L2 9.24l5.45 4.73L5.82 21z"/>',
},
'expand-all': {
body: '<path fill="currentColor" d="M18 8H8v10H6V8a2 2 0 0 1 2-2h10zm-4-6H4a2 2 0 0 0-2 2v10h2V4h10zm8 10v8a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2m-2 3h-3v-3h-2v3h-3v2h3v3h2v-3h3z"/>',
},
},
aliases: {
'more-vert': {
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/components/common/Resource/ScaleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export default function ScaleButton(props: ScaleButtonProps) {
return (
<AuthVisible
item={item}
authVerb="update"
authVerb="patch"
subresource="scale"
onError={(err: Error) => {
console.error(`Error while getting authorization for scaling button in ${item}:`, err);
}}
Expand All @@ -90,7 +91,7 @@ export default function ScaleButton(props: ScaleButtonProps) {
setOpenDialog(true);
}}
>
<Icon icon="mdi:content-copy" />
<Icon icon="mdi:expand-all" />
</IconButton>
</Tooltip>
<ScaleDialog resource={item} open={openDialog} onClose={handleClose} onSave={handleSave} />
Expand Down Expand Up @@ -162,16 +163,17 @@ function ScaleDialog(props: ScaleDialogProps) {
<Fab
size="small"
color="primary"
onClick={() => setNumReplicas(numReplicas => numReplicas - 1)}
onClick={() => setNumReplicas(numReplicas => Math.max(0, numReplicas - 1))}
aria-label={t('translation|Decrement')}
disabled={numReplicas <= 0}
>
<Icon icon="mdi:minus" width="22px" />
</Fab>
<Input
type="number"
value={numReplicas}
sx={{ marginLeft: '6px', marginRight: '6px' }}
onChange={e => setNumReplicas(Number(e.target.value))}
onChange={e => setNumReplicas(Math.max(0, Number(e.target.value)))}
aria-labelledby={desiredNumReplicasLabel}
inputProps={{
min: 0,
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/lib/k8s/apiProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,18 @@ function apiScaleFactory(apiRoot: string, resource: string) {
const cluster = clusterName || getCluster() || '';
return put(url(body.metadata.namespace!, body.metadata.name), body, undefined, { cluster });
},
patch: (
body: {
spec: {
replicas: number;
};
},
metadata: KubeMetadata,
clusterName?: string
) => {
const cluster = clusterName || getCluster() || '';
return patch(url(metadata.namespace!, metadata.name), body, false, { cluster });
},
};

function url(namespace: string, name: string) {
Expand Down Expand Up @@ -985,7 +997,7 @@ export function patch(
const opts = {
method: 'PATCH',
body,
headers: { ...JSON_HEADERS, 'Content-Type': 'application/json-patch+json' },
headers: { ...JSON_HEADERS, 'Content-Type': 'application/merge-patch+json' },
autoLogoutOnAuthError,
cluster,
...requestOptions,
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/lib/k8s/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,18 +686,19 @@ export function makeKubeObject<T extends KubeObjectInterface | KubeEvent>(

type ApiEndpointWithScale = {
scale: {
put: (
data: { metadata: KubeMetadata; spec: { replicas: number } },
patch: (
body: { spec: { replicas: number } },
metadata: KubeMetadata,
clusterName?: string
) => Promise<any>;
};
};

return (this._class().apiEndpoint as ApiEndpointWithScale).scale.put(
return (this._class().apiEndpoint as ApiEndpointWithScale).scale.patch(
{
metadata: this.metadata,
spec,
},
this.metadata,
this._clusterName
);
}
Expand Down

0 comments on commit 45a0dc5

Please sign in to comment.