コード例 #1
0
    public async Task ScopeProvidedByGenerateParameter(string scope)
    {
        var generator = new CustomResourceDefinitionGenerator();

        var crd = await generator.GenerateCustomResourceDefinitionAsync <SimpleResource>(scope);

        Assert.Equal(scope, crd.Spec.Scope);
    }
コード例 #2
0
    public async Task MetadataNameComesFromPluralNameAndGroup()
    {
        var generator = new CustomResourceDefinitionGenerator();

        var crd = await generator.GenerateCustomResourceDefinitionAsync <SimpleResource>("Namespaced");

        Assert.Equal("testkinds.test-group", crd.Name());
    }
コード例 #3
0
    public async Task GroupAndNamesComesFromKubernetesEntityAttribute(Type resourceType, string group, string kind, string plural)
    {
        var generator = new CustomResourceDefinitionGenerator();

        var crd = await generator.GenerateCustomResourceDefinitionAsync(resourceType, "Namespaced");

        Assert.Equal(group, crd.Spec.Group);
        Assert.Equal(kind, crd.Spec.Names.Kind);
        Assert.Equal(plural, crd.Spec.Names.Plural);
    }
コード例 #4
0
    public async Task CreateWithSingleVersionThatIsStoredAndServed(Type resourceType, string version)
    {
        var generator = new CustomResourceDefinitionGenerator();

        var crd = await generator.GenerateCustomResourceDefinitionAsync(resourceType, "Namespaced");

        var crdVersion = Assert.Single(crd.Spec.Versions);

        Assert.Equal(version, crdVersion.Name);
        Assert.True(crdVersion.Served);
        Assert.True(crdVersion.Storage);
    }
コード例 #5
0
    public async Task ApiVersionAndKindAreCorrect()
    {
        var generator = new CustomResourceDefinitionGenerator();

        var crd = await generator.GenerateCustomResourceDefinitionAsync <SimpleResource>("Namespaced");

        Assert.Equal("v1", crd.ApiGroupVersion());
        Assert.Equal(V1CustomResourceDefinition.KubeApiVersion, crd.ApiGroupVersion());
        Assert.Equal("apiextensions.k8s.io", crd.ApiGroup());
        Assert.Equal(V1CustomResourceDefinition.KubeGroup, crd.ApiGroup());
        Assert.Equal("CustomResourceDefinition", crd.Kind);
        Assert.Equal(V1CustomResourceDefinition.KubeKind, crd.Kind);
        crd.Validate();
    }
コード例 #6
0
    public async Task DescriptionsComeFromDocComments()
    {
        var generator = new CustomResourceDefinitionGenerator();

        var crd = await generator.GenerateCustomResourceDefinitionAsync <TypicalResource>("Namespaced");

        Assert.NotNull(crd.Spec);
        var version = Assert.Single(crd.Spec.Versions);

        Assert.NotNull(version.Schema);
        var schema = version.Schema.OpenAPIV3Schema;

        Assert.NotNull(schema);

        Assert.Contains("TypicalResource doc comment", schema.Description, StringComparison.Ordinal);
        Assert.Contains("Spec doc comment", schema.Properties["spec"].Description, StringComparison.Ordinal);
        Assert.Contains("Status doc comment", schema.Properties["status"].Description, StringComparison.Ordinal);
    }
コード例 #7
0
    public async Task TypicalResourceHasSchema()
    {
        var generator = new CustomResourceDefinitionGenerator();

        var crd = await generator.GenerateCustomResourceDefinitionAsync <TypicalResource>("Namespaced");

        Assert.NotNull(crd.Spec);
        var version = Assert.Single(crd.Spec.Versions);

        Assert.NotNull(version.Schema);
        var schema = version.Schema.OpenAPIV3Schema;

        Assert.NotNull(schema);

        Assert.Equal(new[] { "apiVersion", "kind", "metadata", "spec", "status" }, schema.Properties.Keys);

        Assert.Equal("string", schema.Properties["apiVersion"].Type);
        Assert.Equal("string", schema.Properties["kind"].Type);
        Assert.Equal("object", schema.Properties["metadata"].Type);
        Assert.Equal("object", schema.Properties["spec"].Type);
        Assert.Equal("object", schema.Properties["status"].Type);
    }