@@ -1139,6 +1139,74 @@ func (p *ProjectRunner) UpdateProcess(updated *types.ProcessConfig) error {
11391139 return nil
11401140}
11411141
1142+ // AddNamespace adds processes that all belong to the same namespace.
1143+ // If the namespace already exists in the current project, an error is returned.
1144+ func (p * ProjectRunner ) AddNamespace (processes * types.Processes ) (map [string ]string , error ) {
1145+ status := make (map [string ]string )
1146+ if processes == nil || len (* processes ) == 0 {
1147+ return status , fmt .Errorf ("no processes provided" )
1148+ }
1149+
1150+ // Determine namespace from first process and validate uniformity
1151+ ns := ""
1152+ for _ , pr := range * processes {
1153+ if ns == "" {
1154+ ns = pr .Namespace
1155+ } else if pr .Namespace != ns {
1156+ return status , fmt .Errorf ("all processes must be in the same namespace" )
1157+ }
1158+ }
1159+ // Check if namespace already exists
1160+ for _ , exist := range p .project .Processes {
1161+ if exist .Namespace == ns {
1162+ return status , fmt .Errorf ("namespace %s already exists" , ns )
1163+ }
1164+ }
1165+
1166+ // Render, assign, and add all processes
1167+ tpl := templater .New (p .project .Vars )
1168+ for name , pr := range * processes {
1169+ if pr .Name == "" {
1170+ pr .Name = name
1171+ }
1172+ if pr .Namespace == "" {
1173+ pr .Namespace = ns
1174+ }
1175+ pr .ReplicaName = pr .CalculateReplicaName ()
1176+ validateProbes (pr .LivenessProbe )
1177+ validateProbes (pr .ReadinessProbe )
1178+ tpl .RenderProcess (& pr )
1179+ pr .AssignProcessExecutableAndArgs (p .project .ShellConfig , p .project .GetElevatedShellArg ())
1180+ p .addProcessAndRun (pr )
1181+ status [pr .ReplicaName ] = types .ProcessUpdateAdded
1182+ }
1183+ return status , nil
1184+ }
1185+
1186+ // RemoveNamespace deletes all processes belonging to the given namespace.
1187+ func (p * ProjectRunner ) RemoveNamespace (namespace string ) (map [string ]string , error ) {
1188+ removed := make (map [string ]string )
1189+ var errs []error
1190+ names := make ([]string , 0 )
1191+
1192+ // Collect names first to avoid mutating during iteration
1193+ for name , proc := range p .project .Processes {
1194+ if proc .Namespace == namespace {
1195+ names = append (names , name )
1196+ }
1197+ }
1198+
1199+ for _ , name := range names {
1200+ if err := p .removeProcess (name ); err != nil {
1201+ removed [name ] = err .Error ()
1202+ errs = append (errs , err )
1203+ } else {
1204+ removed [name ] = types .ProcessUpdateRemoved
1205+ }
1206+ }
1207+ return removed , errors .Join (errs ... )
1208+ }
1209+
11421210func (p * ProjectRunner ) prepareEnvCmds () {
11431211 for env , cmd := range p .project .EnvCommands {
11441212 output , err := runCmd (cmd )
0 commit comments