From 6521cffdddad38527be1686b753b68496452e522 Mon Sep 17 00:00:00 2001 From: Tamir David Date: Fri, 10 Jan 2025 15:38:57 +0200 Subject: [PATCH] chore: verify profile exists before installing (#2162) Co-authored-by: Amir Blum --- cli/cmd/install.go | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/cli/cmd/install.go b/cli/cmd/install.go index ccb2a367c..f8173b91a 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -99,6 +99,9 @@ This command will install k8s components that will auto-instrument your applicat odigosProToken = odigosOnPremToken } + // validate user input profiles against available profiles + validateUserInputProfiles(odigosTier) + config := createOdigosConfig(odigosTier) fmt.Printf("Installing Odigos version %s in namespace %s ...\n", versionFlag, ns) @@ -182,25 +185,33 @@ func createNamespace(ctx context.Context, cmd *cobra.Command, client *kube.Clien return nil } +func validateUserInputProfiles(tier common.OdigosTier) { + // Fetch available profiles for the given tier + availableProfiles := resources.GetAvailableProfilesForTier(tier) + + // Create a map for fast lookups of valid profile names + profileMap := make(map[string]struct{}) + for _, profile := range availableProfiles { + profileMap[string(profile.ProfileName)] = struct{}{} + } + + // Check each user input profile against the map + for _, input := range userInputInstallProfiles { + if _, exists := profileMap[input]; !exists { + fmt.Printf("\033[31mERROR\033[0m Profile '%s' not available.\n", input) + os.Exit(1) + } + } +} + func createOdigosConfig(odigosTier common.OdigosTier) common.OdigosConfiguration { fullIgnoredNamespaces := utils.MergeDefaultIgnoreWithUserInput(userInputIgnoredNamespaces, consts.SystemNamespaces) fullIgnoredContainers := utils.MergeDefaultIgnoreWithUserInput(userInputIgnoredContainers, consts.IgnoredContainers) selectedProfiles := []common.ProfileName{} - profiles := resources.GetAvailableProfilesForTier(odigosTier) + for _, profile := range userInputInstallProfiles { - found := false - for _, p := range profiles { - if string(p.ProfileName) == profile { - found = true - break - } - } - if !found { - fmt.Printf("\033[34mINFO\033[0m Profile '%s' skipped - not available for tier '%s'.\n", profile, odigosTier) - } else { - selectedProfiles = append(selectedProfiles, common.ProfileName(profile)) - } + selectedProfiles = append(selectedProfiles, common.ProfileName(profile)) } return common.OdigosConfiguration{