-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating DraftConfig to contain more metadata (#381)
- Loading branch information
Showing
28 changed files
with
573 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/Azure/draft/template" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var allTemplates = map[string]*DraftConfig{} | ||
|
||
var validTemplateTypes = map[string]bool{ | ||
"manifest": true, | ||
"dockerfile": true, | ||
"workflow": true, | ||
"deployment": true, | ||
} | ||
|
||
var validVariableTypes = map[string]bool{ | ||
"string": true, | ||
"bool": true, | ||
"int": true, | ||
"float": true, | ||
"object": true, | ||
} | ||
var validVariableKinds = map[string]bool{ | ||
"azureContainerRegistry": true, | ||
"azureKeyvaultUri": true, | ||
"azureManagedCluster": true, | ||
"azureResourceGroup": true, | ||
"azureServiceConnection": true, | ||
"containerImageName": true, | ||
"containerImageVersion": true, | ||
"dirPath": true, | ||
"filePath": true, | ||
"flag": true, | ||
"helmChartOverrides": true, | ||
"ingressHostName": true, | ||
"kubernetesNamespace": true, | ||
"kubernetesResourceName": true, | ||
"label": true, | ||
"port": true, | ||
"repositoryBranch": true, | ||
"workflowName": true, | ||
} | ||
|
||
/* | ||
This test will validate all the templates in the templates directory have: | ||
1. a unique template name | ||
2. a valid template type | ||
3. a non-empty variable name | ||
4. a valid variable type | ||
5. a valid variable kind | ||
Append this for more validation | ||
*/ | ||
func TestTempalteValidation(t *testing.T) { | ||
assert.Nil(t, loadTemplatesWithValidation()) | ||
} | ||
|
||
func loadTemplatesWithValidation() error { | ||
return fs.WalkDir(template.Templates, ".", func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if d.IsDir() { | ||
return nil | ||
} | ||
|
||
if !strings.EqualFold(d.Name(), draftConfigFile) { | ||
return nil | ||
} | ||
|
||
currTemplate, err := NewConfigFromFS(template.Templates, path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if currTemplate == nil { | ||
return fmt.Errorf("template %s is nil", path) | ||
} | ||
|
||
if currTemplate.TemplateName == "" { | ||
return fmt.Errorf("template %s has no template name", path) | ||
} | ||
|
||
if _, ok := allTemplates[currTemplate.TemplateName]; ok { | ||
return fmt.Errorf("template %s has a duplicate template name", path) | ||
} | ||
|
||
if _, ok := validTemplateTypes[currTemplate.Type]; !ok { | ||
return fmt.Errorf("template %s has an invalid type: %s", path, currTemplate.Type) | ||
} | ||
|
||
for _, variable := range currTemplate.Variables { | ||
if variable.Name == "" { | ||
return fmt.Errorf("template %s has a variable with no name", path) | ||
} | ||
|
||
if _, ok := validVariableTypes[variable.Type]; !ok { | ||
return fmt.Errorf("template %s has an invalid variable(%s) type: %s", path, variable.Name, variable.Type) | ||
} | ||
|
||
if _, ok := validVariableKinds[variable.Kind]; !ok { | ||
return fmt.Errorf("template %s has an invalid variable kind: %s", path, variable.Kind) | ||
} | ||
} | ||
return nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,53 @@ | ||
templateName: "azure-pipeline-kustomize" | ||
description: "This template is used to create an Azure Pipeline for deploying an app to AKS using Kustomize" | ||
type: "workflow" | ||
variables: | ||
- name: "PIPELINENAME" | ||
type: "string" | ||
kind: "workflowName" | ||
default: | ||
value: "Build and deploy an app to AKS" | ||
description: "the name of the azure pipeline" | ||
- name: "BRANCHNAME" | ||
type: "string" | ||
kind: "repositoryBranch" | ||
default: | ||
value: "main" | ||
description: "the branch to trigger the pipeline" | ||
- name: "ARMSERVICECONNECTION" | ||
type: "string" | ||
kind: "azureServiceConnection" | ||
description: "the name of the Azure Resource Manager service connection" | ||
- name: "AZURECONTAINERREGISTRY" | ||
type: "string" | ||
kind: "azureContainerRegistry" | ||
description: "the name of the Azure Container Registry" | ||
- name: "CONTAINERNAME" | ||
type: "string" | ||
kind: "containerImageName" | ||
description: "the container image name" | ||
- name: "CLUSTERRESOURCEGROUP" | ||
type: "string" | ||
kind: "azureResourceGroup" | ||
description: "the AKS cluster resource group" | ||
- name: "ACRRESOURCEGROUP" | ||
type: "string" | ||
kind: "azureResourceGroup" | ||
description: "the ACR resource group" | ||
- name: "CLUSTERNAME" | ||
type: "string" | ||
kind: "azureManagedCluster" | ||
description: "the AKS cluster name" | ||
- name: "KUSTOMIZEPATH" | ||
type: "string" | ||
kind: "dirPath" | ||
default: | ||
disablePrompt: true | ||
value: "./overlays/production" # keeping this as default since draft generates the manifests in the overlays/production directory | ||
description: "the path to the Kustomize directory" | ||
- name: "NAMESPACE" | ||
type: "string" | ||
kind: "kubernetesNamespace" | ||
default: | ||
value: "default" | ||
description: "the Kubernetes namespace" | ||
description: "the Kubernetes namespace" |
Oops, something went wrong.