Commit f75d3a07 authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

feat(meepctl): add individual dep deploy/delete and force-deploy cooldown

- Add 'meepctl deploy dep <app>' to deploy a single dependency
- Add 'meepctl delete dep <app>' to delete a single dependency
- Add 5s cooldown between delete and re-deploy when using --force
- Update help text and examples for deploy and delete commands
parent cdaedb82
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ Delete command removes a group of containers from the K8s cluster.`

const deleteExample = `  # Delete dependency containers
  meepctl delete dep
  # Delete a single dependency
  meepctl delete dep meep-couchdb
  # Delete only AdvantEDGE core containers
  meepctl delete core`

@@ -105,11 +107,11 @@ func deleteRun(cmd *cobra.Command, args []string) {
		}
	case "dep":
		if targetApp != "" {
			fmt.Println("Error: Individual app deletion not supported for 'dep' group")
			return
		}
			deleteSingleDepApp(targetApp, cmd)
		} else {
			deleteApps(deleteData.depApps, cmd)
		}
	}

	elapsed := time.Since(start)
	if t {
@@ -123,6 +125,27 @@ func deleteApps(apps []string, cobraCmd *cobra.Command) {
	}
}

// Delete a single dep app
func deleteSingleDepApp(app string, cobraCmd *cobra.Command) {
	// Validate the app is in the dep list
	found := false
	for _, depApp := range deleteData.depApps {
		if depApp == app {
			found = true
			break
		}
	}
	if !found {
		fmt.Println("Error: '" + app + "' is not a valid dep target")
		fmt.Println("Valid dep targets:")
		for _, a := range deleteData.depApps {
			fmt.Println("  * " + a)
		}
		return
	}
	k8sDelete(app, cobraCmd)
}

func k8sDelete(component string, cobraCmd *cobra.Command) {
	// If release exist
	exist, _ := utils.IsHelmRelease(component, cobraCmd)
+32 −4
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ Defaut tag is: latest`

const deployExample = `  # Deploy AdvantEDGE dependencies
  meepctl deploy dep
  # Deploy a single dependency
  meepctl deploy dep meep-couchdb
  # Delete and re-deploy only AdvantEDGE core containers
  meepctl deploy core --force
  # Deploy AdvantEDGE version 1.0.0 from my.registry.com
@@ -155,12 +157,12 @@ func deployRun(cmd *cobra.Command, args []string) {
		}
	case "dep":
		if targetApp != "" {
			fmt.Println("Error: Individual app deployment not supported for 'dep' group")
			return
		}
			deploySingleDepApp(targetApp, cmd)
		} else {
			createCRD(cmd)
			deployDep(cmd)
		}
	}

	elapsed := time.Since(start)
	if t {
@@ -278,6 +280,29 @@ func deployDep(cobraCmd *cobra.Command) {
	}
}

// Deploy a single dep app
func deploySingleDepApp(app string, cobraCmd *cobra.Command) {
	// Validate the app is in the dep list
	found := false
	for _, depApp := range deployData.depApps {
		if depApp == app {
			found = true
			break
		}
	}
	if !found {
		fmt.Println("Error: '" + app + "' is not a valid dep target")
		fmt.Println("Valid dep targets:")
		for _, a := range deployData.depApps {
			fmt.Println("  * " + a)
		}
		return
	}
	chart := deployData.gitdir + "/" + utils.RepoCfg.GetString("repo.dep."+app+".chart")
	flags := deployRunScriptsAndGetFlags(app, chart, cobraCmd)
	k8sDeploy(app, chart, flags, cobraCmd)
}

func deployRunScriptsAndGetFlags(targetName string, chart string, cobraCmd *cobra.Command) [][]string {
	var flags [][]string
	authUrlAnnotation := "ingress.annotations.nginx\\.ingress\\.kubernetes\\.io/auth-url"
@@ -602,6 +627,9 @@ func k8sDeploy(app string, chart string, flags [][]string, cobraCmd *cobra.Comma
	if exist {
		if force {
			_ = utils.HelmDelete(app, cobraCmd)
			// Wait for K8s to clean up resources before redeploying
			fmt.Println("Waiting 5s for resource cleanup...")
			time.Sleep(10 * time.Second)
		} else {
			fmt.Println("Skipping " + app + ": already deployed -- use [-f, --force] flag to force deployment")
			return