Skip to content

Commit

Permalink
chore: verify profile exists before installing (#2162)
Browse files Browse the repository at this point in the history
Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
  • Loading branch information
tamirdavid1 and blumamir authored Jan 10, 2025
1 parent 419f5ea commit 6521cff
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 6521cff

Please sign in to comment.