Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: verify profile exists before installing #2162

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading