-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unify init/deploy & add basic chart validation before create
- Loading branch information
1 parent
d15a3bd
commit 658237f
Showing
7 changed files
with
109 additions
and
36 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 @@ | ||
package helm |
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,82 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"github.com/defenseunicorns/zarf/cli/config" | ||
"github.com/defenseunicorns/zarf/cli/internal/message" | ||
) | ||
|
||
// Run performs config validations and runs message.Fatal() on errors | ||
func Run() { | ||
components := config.GetComponents() | ||
|
||
for _, component := range components { | ||
for _, chart := range component.Charts { | ||
if err := validateChart(chart); err != nil { | ||
message.Fatalf(err, "Invalid chart definition in the %s component: %s", component.Name, err) | ||
} | ||
} | ||
for _, manifest := range component.Manifests { | ||
if err := validateManifest(manifest); err != nil { | ||
message.Fatalf(err, "Invalid manifest definition in the %s component: %s", component.Name, err) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
func validateChart(chart config.ZarfChart) error { | ||
intro := fmt.Sprintf("chart %s", chart.Name) | ||
|
||
// Don't allow empty names | ||
if chart.Name == "" { | ||
return fmt.Errorf("%s must include a name", intro) | ||
} | ||
|
||
// Helm max release name | ||
if len(chart.Name) > config.ZarfMaxChartNameLength { | ||
return fmt.Errorf("%s exceed the maximum length of %d characters", | ||
intro, | ||
config.ZarfMaxChartNameLength) | ||
} | ||
|
||
// Must have a namespace | ||
if chart.Namespace == "" { | ||
return fmt.Errorf("%s must include a namespace", intro) | ||
} | ||
|
||
// Must have a url | ||
if chart.Url == "" { | ||
return fmt.Errorf("%s must include a url", intro) | ||
} | ||
|
||
// Must have a version | ||
if chart.Version == "" { | ||
return fmt.Errorf("%s must include a chart version", intro) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validateManifest(manifest config.ZarfManifest) error { | ||
intro := fmt.Sprintf("chart %s", manifest.Name) | ||
|
||
// Don't allow empty names | ||
if manifest.Name == "" { | ||
return fmt.Errorf("%s must include a name", intro) | ||
} | ||
|
||
// Helm max release name | ||
if len(manifest.Name) > config.ZarfMaxChartNameLength { | ||
return fmt.Errorf("%s exceed the maximum length of %d characters", | ||
intro, | ||
config.ZarfMaxChartNameLength) | ||
} | ||
|
||
// Require files in manifest | ||
if len(manifest.Files) < 1 { | ||
return fmt.Errorf("%s must have at least 1 file", intro) | ||
} | ||
|
||
return nil | ||
} |