Skip to content

Commit c772aed

Browse files
authored
feat: workload is no longer mandatory in the AppConfig (#1246)
1 parent f6d89bb commit c772aed

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

pkg/modules/generators/app_configurations_generator.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,18 @@ func (g *appConfigurationGenerator) Generate(spec *v1.Spec) error {
141141
namespace := g.getNamespaceName()
142142
gfs := []modules.NewGeneratorFunc{
143143
NewNamespaceGeneratorFunc(namespace),
144+
}
145+
146+
if g.app.Workload != nil {
144147
// todo: refactor secret into a module
145-
secret.NewSecretGeneratorFunc(&secret.GeneratorRequest{
148+
gfs = append(gfs, secret.NewSecretGeneratorFunc(&secret.GeneratorRequest{
146149
Project: g.project.Name,
147150
Namespace: namespace,
148151
Workload: g.app.Workload,
149152
SecretStore: g.ws.SecretStore,
150-
}),
153+
}))
151154
}
155+
152156
if err = modules.CallGenerators(spec, gfs...); err != nil {
153157
return err
154158
}
@@ -160,7 +164,9 @@ func (g *appConfigurationGenerator) Generate(spec *v1.Spec) error {
160164
}
161165

162166
// append the generated resources to the spec
163-
spec.Resources = append(spec.Resources, *wl)
167+
if wl != nil {
168+
spec.Resources = append(spec.Resources, *wl)
169+
}
164170
spec.Resources = append(spec.Resources, resources...)
165171

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

255+
if workload == nil {
256+
log.Info("workload is nil, return")
257+
return nil
258+
}
259+
249260
un := &unstructured.Unstructured{}
250261
attributes := workload.Attributes
251262

@@ -500,7 +511,9 @@ func (g *appConfigurationGenerator) buildModuleConfigIndex(platformModuleConfigs
500511
for k, v := range g.app.Accessories {
501512
tempMap[k] = v
502513
}
503-
tempMap["workload"] = g.app.Workload
514+
if g.app.Workload != nil {
515+
tempMap["workload"] = g.app.Workload
516+
}
504517

505518
for accName, accessory := range tempMap {
506519
// parse accessory module key
@@ -525,6 +538,11 @@ func (g *appConfigurationGenerator) buildModuleConfigIndex(platformModuleConfigs
525538
// parseModuleKey returns the module key of the accessory in format of "org/module@version"
526539
// example: "kusionstack/[email protected]"
527540
func parseModuleKey(accessory v1.Accessory, dependencies *pkg.Dependencies) (string, error) {
541+
if accessory == nil {
542+
log.Info("accessory is nil, return empty module key")
543+
return "", nil
544+
}
545+
528546
moduleName, err := getModuleName(accessory)
529547
if err != nil {
530548
return "", err

pkg/modules/generators/secret/secret.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111

1212
v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1"
13+
"kusionstack.io/kusion/pkg/log"
1314
"kusionstack.io/kusion/pkg/modules"
1415
)
1516

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

3940
secretMap := make(map[string]v1.Secret)
41+
42+
if request.Workload == nil {
43+
log.Infof("workload is missing, no secret will be generated")
44+
return &secretGenerator{}, nil
45+
}
4046
secrets := request.Workload["secrets"]
4147
if secrets != nil {
4248
out, err := yaml.Marshal(secrets)

0 commit comments

Comments
 (0)