Skip to content

Commit 3730f6d

Browse files
committed
Add support for uses_kubernetes_features metadata
uses_kubernetes_features is a new tile attribute that allows K8s consumer tiles to restrict which K8s distribution tiles can be assigned to it by matching those features against the distribution's features. This commit updates `kiln carvel bake` to pass through the new attribute. ai-assisted=yes [TNZ-120804] Define available_kubernetes_features / uses_kubernetes_features tile metadata schema
1 parent 6862b6f commit 3730f6d

5 files changed

Lines changed: 65 additions & 0 deletions

File tree

internal/carvel/baker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ func (b *baker) generateBaseYaml() error {
611611
meta.Rank = b.metadata.Rank
612612
meta.Serial = b.metadata.Serial
613613
meta.CompatibleKubernetesDistributions = b.metadata.CompatibleKubernetesDistributions
614+
meta.UsesKubernetesFeatures = b.metadata.UsesKubernetesFeatures
614615
meta.FormTypes = b.metadata.FormTypes
615616
meta.PropertyBlueprints = b.metadata.PropertyBlueprints
616617
meta.Variables = b.metadata.Variables

internal/carvel/baker_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ consumes:
361361
Expect(outMeta.CompatibleKubernetesDistributions[0].Name).To(Equal("k0s"))
362362
Expect(outMeta.CompatibleKubernetesDistributions[0].Version).To(Equal(">0.0.0"))
363363
Expect(outMeta.RequiresKubernetes).To(BeTrue())
364+
Expect(outMeta.UsesKubernetesFeatures).To(HaveLen(2))
365+
Expect(outMeta.UsesKubernetesFeatures[0].Name).To(Equal("gpu-scheduling"))
366+
Expect(outMeta.UsesKubernetesFeatures[0].Optional).To(BeFalse())
367+
Expect(outMeta.UsesKubernetesFeatures[1].Name).To(Equal("node-local-storage"))
368+
Expect(outMeta.UsesKubernetesFeatures[1].Optional).To(BeTrue())
364369
})
365370
It("creates empty instance_group and jobs directories", func() {
366371
Expect(filepath.Join(outputPath, "instance_groups")).To(BeADirectory())
@@ -495,6 +500,51 @@ consumes:
495500
Expect(err.Error()).To(ContainSubstring("tile metadata_version too old"))
496501
})
497502
})
503+
When("the tile declares no kubernetes features", func() {
504+
// Ops Manager rejects uses_kubernetes_features on a tile that is not a
505+
// kubernetes consumer, so an absent block must stay absent rather than
506+
// baking out as an empty list.
507+
BeforeEach(func() {
508+
m := models.Metadata{
509+
Name: "k8s-tile-test",
510+
Label: "test tile",
511+
IconImage: "$( icon )",
512+
MetadataVersion: "3.2.0",
513+
MinimumVersionForUpgrade: "0.0.0",
514+
ProductVersion: "$( version )",
515+
Rank: 1,
516+
Serial: false,
517+
PropertyBlueprints: []string{
518+
`$( property "database_name" )`,
519+
`$( property "admin_password" )`,
520+
},
521+
FormTypes: []string{`$( form "db_props" )`},
522+
Variables: []proofing.Variable{},
523+
PackageInstalls: []string{`$( package "test-install" )`},
524+
CompatibleKubernetesDistributions: []models.ProductVersion{{Name: "k0s", Version: ">0.0.0"}},
525+
}
526+
yamlData, err := yaml.Marshal(&m)
527+
Expect(err).NotTo(HaveOccurred())
528+
Expect(string(yamlData)).NotTo(ContainSubstring("uses_kubernetes_features"))
529+
err = os.WriteFile(path.Join(inputPath, "base.yml"), yamlData, 0644)
530+
Expect(err).NotTo(HaveOccurred())
531+
})
532+
533+
It("omits uses_kubernetes_features from the baked metadata", func() {
534+
Expect(err).NotTo(HaveOccurred())
535+
536+
yamlData, readErr := os.ReadFile(path.Join(outputPath, "base.yml"))
537+
Expect(readErr).NotTo(HaveOccurred())
538+
Expect(string(yamlData)).NotTo(ContainSubstring("uses_kubernetes_features"))
539+
540+
outMeta := models.MetadataOut{}
541+
Expect(yaml.Unmarshal(yamlData, &outMeta)).To(Succeed())
542+
Expect(outMeta.UsesKubernetesFeatures).To(BeEmpty())
543+
// the rest of the kubernetes metadata is unaffected
544+
Expect(outMeta.RequiresKubernetes).To(BeTrue())
545+
Expect(outMeta.CompatibleKubernetesDistributions).To(HaveLen(1))
546+
})
547+
})
498548
})
499549
})
500550

internal/carvel/models/metadata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ type Metadata struct {
1616
Variables []proofing.Variable `yaml:"variables"`
1717
PackageInstalls []string `yaml:"package_installs"`
1818
CompatibleKubernetesDistributions []ProductVersion `yaml:"compatible_kubernetes_distributions,omitempty"`
19+
UsesKubernetesFeatures []KubernetesFeature `yaml:"uses_kubernetes_features,omitempty"`
1920
}

internal/carvel/models/metadata_out.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type MetadataOut struct {
2020
RuntimeConfigs []string `yaml:"runtime_configs"`
2121
RequiresKubernetes bool `yaml:"requires_kubernetes"`
2222
CompatibleKubernetesDistributions []ProductVersion `yaml:"compatible_kubernetes_distributions"`
23+
UsesKubernetesFeatures []KubernetesFeature `yaml:"uses_kubernetes_features,omitempty"`
2324
}
2425

2526
type StemcellCriteria struct {
@@ -31,3 +32,11 @@ type ProductVersion struct {
3132
Name string `yaml:"name"`
3233
Version string `yaml:"version"`
3334
}
35+
36+
// KubernetesFeature is a single entry in a consumer tile's uses_kubernetes_features.
37+
// Optional is omitted when false so that baked metadata matches the source tile: Ops
38+
// Manager already defaults an absent optional to false.
39+
type KubernetesFeature struct {
40+
Name string `yaml:"name"`
41+
Optional bool `yaml:"optional,omitempty"`
42+
}

internal/carvel/testdata/sample-tile/base.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ package_installs:
2323
compatible_kubernetes_distributions:
2424
- name: k0s
2525
version: '>0.0.0'
26+
uses_kubernetes_features:
27+
- name: gpu-scheduling
28+
- name: node-local-storage
29+
optional: true

0 commit comments

Comments
 (0)