Skip to content

Commit a38bad1

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 167cb53 commit a38bad1

5 files changed

Lines changed: 62 additions & 0 deletions

File tree

internal/carvel/baker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ func (b *baker) generateBaseYaml() error {
661661
meta.CompatibleKubernetesDistributions = b.metadata.CompatibleKubernetesDistributions
662662
meta.SupportsParallelDeploys = b.metadata.SupportsParallelDeploys
663663
meta.RequiresProductVersions = b.metadata.RequiresProductVersions
664+
meta.UsesKubernetesFeatures = b.metadata.UsesKubernetesFeatures
664665
meta.FormTypes = b.metadata.FormTypes
665666
meta.PropertyBlueprints = b.metadata.PropertyBlueprints
666667
meta.Variables = b.metadata.Variables

internal/carvel/baker_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ consumes:
418418
Expect(outMeta.RequiresProductVersions[0].Name).To(Equal("some-other-product"))
419419
Expect(outMeta.RequiresProductVersions[0].Version).To(Equal(">=1.0.0"))
420420
Expect(outMeta.RequiresProductVersions[0].Optional).To(BeTrue())
421+
Expect(outMeta.UsesKubernetesFeatures).To(HaveLen(2))
422+
Expect(outMeta.UsesKubernetesFeatures[0].Name).To(Equal("gpu-scheduling"))
423+
Expect(outMeta.UsesKubernetesFeatures[0].Optional).To(BeFalse())
424+
Expect(outMeta.UsesKubernetesFeatures[1].Name).To(Equal("node-local-storage"))
425+
Expect(outMeta.UsesKubernetesFeatures[1].Optional).To(BeTrue())
421426
})
422427
It("creates empty instance_group and jobs directories", func() {
423428
Expect(filepath.Join(outputPath, "instance_groups")).To(BeADirectory())
@@ -600,6 +605,51 @@ consumes:
600605
Expect(outMeta.RequiresProductVersions).To(BeEmpty())
601606
})
602607
})
608+
When("the tile declares no kubernetes features", func() {
609+
// Ops Manager rejects uses_kubernetes_features on a tile that is not a
610+
// kubernetes consumer, so an absent block must stay absent rather than
611+
// baking out as an empty list.
612+
BeforeEach(func() {
613+
m := models.Metadata{
614+
Name: "k8s-tile-test",
615+
Label: "test tile",
616+
IconImage: "$( icon )",
617+
MetadataVersion: "3.2.0",
618+
MinimumVersionForUpgrade: "0.0.0",
619+
ProductVersion: "$( version )",
620+
Rank: 1,
621+
Serial: false,
622+
PropertyBlueprints: []string{
623+
`$( property "database_name" )`,
624+
`$( property "admin_password" )`,
625+
},
626+
FormTypes: []string{`$( form "db_props" )`},
627+
Variables: []proofing.Variable{},
628+
PackageInstalls: []string{`$( package "test-install" )`},
629+
CompatibleKubernetesDistributions: []models.ProductVersion{{Name: "k0s", Version: ">0.0.0"}},
630+
}
631+
yamlData, err := yaml.Marshal(&m)
632+
Expect(err).NotTo(HaveOccurred())
633+
Expect(string(yamlData)).NotTo(ContainSubstring("uses_kubernetes_features"))
634+
err = os.WriteFile(path.Join(inputPath, "base.yml"), yamlData, 0644)
635+
Expect(err).NotTo(HaveOccurred())
636+
})
637+
638+
It("omits uses_kubernetes_features from the baked metadata", func() {
639+
Expect(err).NotTo(HaveOccurred())
640+
641+
yamlData, readErr := os.ReadFile(path.Join(outputPath, "base.yml"))
642+
Expect(readErr).NotTo(HaveOccurred())
643+
Expect(string(yamlData)).NotTo(ContainSubstring("uses_kubernetes_features"))
644+
645+
outMeta := models.MetadataOut{}
646+
Expect(yaml.Unmarshal(yamlData, &outMeta)).To(Succeed())
647+
Expect(outMeta.UsesKubernetesFeatures).To(BeEmpty())
648+
// the rest of the kubernetes metadata is unaffected
649+
Expect(outMeta.RequiresKubernetes).To(BeTrue())
650+
Expect(outMeta.CompatibleKubernetesDistributions).To(HaveLen(1))
651+
})
652+
})
603653
})
604654
})
605655

internal/carvel/models/metadata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ type Metadata struct {
1818
CompatibleKubernetesDistributions []ProductVersion `yaml:"compatible_kubernetes_distributions,omitempty"`
1919
SupportsParallelDeploys bool `yaml:"supports_parallel_deploys,omitempty"`
2020
RequiresProductVersions []RequiredProductVersion `yaml:"requires_product_versions,omitempty"`
21+
UsesKubernetesFeatures []KubernetesFeature `yaml:"uses_kubernetes_features,omitempty"`
2122
}

internal/carvel/models/metadata_out.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type MetadataOut struct {
2222
CompatibleKubernetesDistributions []ProductVersion `yaml:"compatible_kubernetes_distributions"`
2323
SupportsParallelDeploys bool `yaml:"supports_parallel_deploys,omitempty"`
2424
RequiresProductVersions []RequiredProductVersion `yaml:"requires_product_versions,omitempty"`
25+
UsesKubernetesFeatures []KubernetesFeature `yaml:"uses_kubernetes_features,omitempty"`
2526
}
2627

2728
type StemcellCriteria struct {
@@ -39,3 +40,8 @@ type RequiredProductVersion struct {
3940
Version string `yaml:"version"`
4041
Optional bool `yaml:"optional,omitempty"`
4142
}
43+
44+
type KubernetesFeature struct {
45+
Name string `yaml:"name"`
46+
Optional bool `yaml:"optional,omitempty"`
47+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ requires_product_versions:
2828
- name: some-other-product
2929
version: '>=1.0.0'
3030
optional: true
31+
uses_kubernetes_features:
32+
- name: gpu-scheduling
33+
- name: node-local-storage
34+
optional: true

0 commit comments

Comments
 (0)