Skip to content

Commit

Permalink
feat: workload is no longer mandatory in the AppConfig (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkYuan authored Jul 31, 2024
1 parent f6d89bb commit c772aed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pkg/modules/generators/app_configurations_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,18 @@ func (g *appConfigurationGenerator) Generate(spec *v1.Spec) error {
namespace := g.getNamespaceName()
gfs := []modules.NewGeneratorFunc{
NewNamespaceGeneratorFunc(namespace),
}

if g.app.Workload != nil {
// todo: refactor secret into a module
secret.NewSecretGeneratorFunc(&secret.GeneratorRequest{
gfs = append(gfs, secret.NewSecretGeneratorFunc(&secret.GeneratorRequest{
Project: g.project.Name,
Namespace: namespace,
Workload: g.app.Workload,
SecretStore: g.ws.SecretStore,
}),
}))
}

if err = modules.CallGenerators(spec, gfs...); err != nil {
return err
}
Expand All @@ -160,7 +164,9 @@ func (g *appConfigurationGenerator) Generate(spec *v1.Spec) error {
}

// append the generated resources to the spec
spec.Resources = append(spec.Resources, *wl)
if wl != nil {
spec.Resources = append(spec.Resources, *wl)
}
spec.Resources = append(spec.Resources, resources...)

// patch workload with resource patchers
Expand Down Expand Up @@ -246,6 +252,11 @@ func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error {
return nil
}

if workload == nil {
log.Info("workload is nil, return")
return nil
}

un := &unstructured.Unstructured{}
attributes := workload.Attributes

Expand Down Expand Up @@ -500,7 +511,9 @@ func (g *appConfigurationGenerator) buildModuleConfigIndex(platformModuleConfigs
for k, v := range g.app.Accessories {
tempMap[k] = v
}
tempMap["workload"] = g.app.Workload
if g.app.Workload != nil {
tempMap["workload"] = g.app.Workload
}

for accName, accessory := range tempMap {
// parse accessory module key
Expand All @@ -525,6 +538,11 @@ func (g *appConfigurationGenerator) buildModuleConfigIndex(platformModuleConfigs
// parseModuleKey returns the module key of the accessory in format of "org/module@version"
// example: "kusionstack/[email protected]"
func parseModuleKey(accessory v1.Accessory, dependencies *pkg.Dependencies) (string, error) {
if accessory == nil {
log.Info("accessory is nil, return empty module key")
return "", nil
}

moduleName, err := getModuleName(accessory)
if err != nil {
return "", err
Expand Down
6 changes: 6 additions & 0 deletions pkg/modules/generators/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1"
"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/modules"
)

Expand Down Expand Up @@ -37,6 +38,11 @@ func NewSecretGenerator(request *GeneratorRequest) (modules.Generator, error) {
}

secretMap := make(map[string]v1.Secret)

if request.Workload == nil {
log.Infof("workload is missing, no secret will be generated")
return &secretGenerator{}, nil
}
secrets := request.Workload["secrets"]
if secrets != nil {
out, err := yaml.Marshal(secrets)
Expand Down

0 comments on commit c772aed

Please sign in to comment.