Skip to content

Commit d5e1f85

Browse files
committed
fix: do not allow using static infra providers in the machine classes
Auto-provision mode should be disabled for them. This change has two parts: 1. Filter the static providers in the UI. 2. Block creating machine classes which reference infra provider with the `is-static-infra-provider` label set. Signed-off-by: Artem Chernyshev <[email protected]>
1 parent d1b3dff commit d5e1f85

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

client/pkg/omni/resources/omni/labels.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const (
6060

6161
// LabelIsStaticInfraProvider is set on the infra.ProviderStatus resources to mark them as static providers - they do not work with MachineRequests to
6262
// allocate and de-allocate machines, but rather work with a static set of machines (e.g., bare-metal machines).
63+
// tsgen:LabelIsStaticInfraProvider
6364
LabelIsStaticInfraProvider = SystemLabelPrefix + "is-static-infra-provider"
6465

6566
// LabelMachineClassName is the name of the machine class.

frontend/src/api/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export const LabelMachine = "omni.sidero.dev/machine";
126126
export const LabelSystemPatch = "omni.sidero.dev/system-patch";
127127
export const LabelExposedServiceAlias = "omni.sidero.dev/exposed-service-alias";
128128
export const LabelInfraProviderID = "omni.sidero.dev/infra-provider-id";
129+
export const LabelIsStaticInfraProvider = "omni.sidero.dev/is-static-infra-provider";
129130
export const LabelMachineRequest = "omni.sidero.dev/machine-request";
130131
export const LabelMachineRequestSet = "omni.sidero.dev/machine-request-set";
131132
export const LabelNoManualAllocation = "omni.sidero.dev/no-manual-allocation";

frontend/src/views/omni/MachineClasses/ProviderConfig.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ included in the LICENSE file.
66
-->
77
<template>
88
<div class="text-naturals-N13">Infrastructure Provider</div>
9-
<t-list :opts="{resource: { type: InfraProviderStatusType, namespace: InfraProviderNamespace }, runtime: Runtime.Omni}" :key="infraProvider" :search="showAllProviders" class="mb-1">
9+
<t-list :opts="infraProviderResources" :key="infraProvider" :search="showAllProviders" class="mb-1">
1010
<template #default="{ items, searchQuery }">
1111
<div class="flex md:flex-col gap-2 max-md:flex-wrap">
1212
<div v-for="item in filterProviders(items)"
@@ -43,13 +43,20 @@ included in the LICENSE file.
4343
import { Runtime } from '@/api/common/omni.pb';
4444
import { Resource } from '@/api/grpc';
4545
import { InfraProviderStatusSpec } from '@/api/omni/specs/infra.pb';
46-
import { InfraProviderNamespace, InfraProviderStatusType } from '@/api/resources';
46+
import { InfraProviderNamespace, InfraProviderStatusType, LabelIsStaticInfraProvider } from '@/api/resources';
4747
import { computed, ref, toRefs } from 'vue';
4848
4949
import TIcon from '@/components/common/Icon/TIcon.vue';
5050
import WordHighlighter from "vue-word-highlighter";
5151
import IconButton from '@/components/common/Button/IconButton.vue';
5252
import TList from '@/components/common/List/TList.vue';
53+
import { WatchOptions } from '@/api/watch';
54+
55+
const infraProviderResources: WatchOptions = {
56+
resource: { type: InfraProviderStatusType, namespace: InfraProviderNamespace },
57+
runtime: Runtime.Omni,
58+
selectors: [`!${LabelIsStaticInfraProvider}`],
59+
};
5360
5461
const props = defineProps<{
5562
infraProvider?: string

internal/backend/runtime/omni/state_validation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,10 @@ func validateProviderData(ctx context.Context, st state.State, providerID, provi
10721072
return fmt.Errorf("failed to get provider: %w", err)
10731073
}
10741074

1075+
if _, static := providerStatus.Metadata().Labels().Get(omni.LabelIsStaticInfraProvider); static {
1076+
return fmt.Errorf("cannot use static provider in the auto-provisioned machine class")
1077+
}
1078+
10751079
return validateSchema(providerStatus)
10761080
}
10771081

internal/backend/runtime/omni/state_validation_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,12 @@ func TestMachineClassValidation(t *testing.T) {
973973
providerStatus := infra.NewProviderStatus("exists")
974974
providerStatus.TypedSpec().Value.Schema = string(schema)
975975

976+
staticProvider := infra.NewProviderStatus("static")
977+
staticProvider.Metadata().Labels().Set(omnires.LabelIsStaticInfraProvider, "")
978+
976979
require.NoError(t, st.Create(ctx, talosVersion))
977980
require.NoError(t, st.Create(ctx, providerStatus))
981+
require.NoError(t, st.Create(ctx, staticProvider))
978982

979983
// no provider id
980984

@@ -1029,8 +1033,20 @@ disk: 1TB
10291033

10301034
require.True(t, validated.IsValidationError(err), "expected validation error")
10311035

1036+
// static infra provider usage is not allowed
1037+
1038+
machineClass.TypedSpec().Value.AutoProvision.ProviderId = staticProvider.Metadata().ID()
1039+
1040+
err = st.Create(ctx, machineClass)
1041+
1042+
require.Error(t, err)
1043+
1044+
require.True(t, validated.IsValidationError(err), "expected validation error")
1045+
10321046
// valid
10331047

1048+
machineClass.TypedSpec().Value.AutoProvision.ProviderId = providerStatus.Metadata().ID()
1049+
10341050
machineClass.TypedSpec().Value.AutoProvision.ProviderData = `
10351051
size: t2.small
10361052
`

0 commit comments

Comments
 (0)