From 003d76727d02edba59bcf453e334eb4220f8a500 Mon Sep 17 00:00:00 2001 From: Dustin Row Date: Tue, 17 Sep 2024 21:14:47 -0700 Subject: [PATCH] Support passing namespace reference via command line option to OSD operator SaaS promotions --- cmd/promote/git/app_interface.go | 15 ++++++++++++--- cmd/promote/saas/saas.go | 4 +++- cmd/promote/saas/utils.go | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cmd/promote/git/app_interface.go b/cmd/promote/git/app_interface.go index 973ddb192..646aa7f8f 100644 --- a/cmd/promote/git/app_interface.go +++ b/cmd/promote/git/app_interface.go @@ -83,7 +83,7 @@ func checkAppInterfaceCheckout(directory string) error { return nil } -func GetCurrentGitHashFromAppInterface(saarYamlFile []byte, serviceName string) (string, string, error) { +func GetCurrentGitHashFromAppInterface(saarYamlFile []byte, serviceName string, namespaceRef string) (string, string, error) { var currentGitHash string var serviceRepo string var service Service @@ -92,7 +92,16 @@ func GetCurrentGitHashFromAppInterface(saarYamlFile []byte, serviceName string) log.Fatal(fmt.Errorf("cannot unmarshal yaml data of service %s: %v", serviceName, err)) } - if service.Name == "saas-configuration-anomaly-detection-db" { + if namespaceRef != "" { + for _, resourceTemplate := range service.ResourceTemplates { + for _, target := range resourceTemplate.Targets { + if strings.Contains(target.Namespace["$ref"], namespaceRef) { + currentGitHash = target.Ref + break + } + } + } + } else if service.Name == "saas-configuration-anomaly-detection-db" { for _, resourceTemplate := range service.ResourceTemplates { for _, target := range resourceTemplate.Targets { if strings.Contains(target.Namespace["$ref"], "app-sre-observability-production-int.yml") { @@ -113,7 +122,7 @@ func GetCurrentGitHashFromAppInterface(saarYamlFile []byte, serviceName string) } else if strings.Contains(service.Name, "rhobs-rules-and-dashboards") { for _, resourceTemplate := range service.ResourceTemplates { for _, target := range resourceTemplate.Targets { - if strings.Contains(service.Name, "rhobsp02ue1-production") { + if strings.Contains(service.Name, "production") { currentGitHash = target.Ref break } diff --git a/cmd/promote/saas/saas.go b/cmd/promote/saas/saas.go index ccdcb88e3..110c8caf6 100644 --- a/cmd/promote/saas/saas.go +++ b/cmd/promote/saas/saas.go @@ -16,6 +16,7 @@ type saasOptions struct { appInterfaceCheckoutDir string serviceName string gitHash string + namespaceRef string } // newCmdSaas implementes the saas command to interact with promoting SaaS services/operators @@ -54,7 +55,7 @@ func NewCmdSaas() *cobra.Command { os.Exit(1) } - err := servicePromotion(appInterface, ops.serviceName, ops.gitHash, ops.osd, ops.hcp) + err := servicePromotion(appInterface, ops.serviceName, ops.gitHash, ops.namespaceRef, ops.osd, ops.hcp) if err != nil { fmt.Printf("Error while promoting service: %v\n", err) os.Exit(1) @@ -68,6 +69,7 @@ func NewCmdSaas() *cobra.Command { saasCmd.Flags().BoolVarP(&ops.list, "list", "l", false, "List all SaaS services/operators") saasCmd.Flags().StringVarP(&ops.serviceName, "serviceName", "", "", "SaaS service/operator getting promoted") saasCmd.Flags().StringVarP(&ops.gitHash, "gitHash", "g", "", "Git hash of the SaaS service/operator commit getting promoted") + saasCmd.Flags().StringVarP(&ops.namespaceRef, "namespaceRef", "n", "", "SaaS target namespace reference name") saasCmd.Flags().BoolVarP(&ops.osd, "osd", "", false, "OSD service/operator getting promoted") saasCmd.Flags().BoolVarP(&ops.hcp, "hcp", "", false, "HCP service/operator getting promoted") saasCmd.Flags().StringVarP(&ops.appInterfaceCheckoutDir, "appInterfaceDir", "", "", "location of app-interfache checkout. Falls back to `pwd` and "+git.DefaultAppInterfaceDirectory()) diff --git a/cmd/promote/saas/utils.go b/cmd/promote/saas/utils.go index a9d0b467f..c3e2217af 100644 --- a/cmd/promote/saas/utils.go +++ b/cmd/promote/saas/utils.go @@ -36,7 +36,7 @@ func listServiceNames(appInterface git.AppInterface) error { return nil } -func servicePromotion(appInterface git.AppInterface, serviceName, gitHash string, osd, hcp bool) error { +func servicePromotion(appInterface git.AppInterface, serviceName, gitHash string, namespaceRef string, osd, hcp bool) error { _, err := GetServiceNames(appInterface, OSDSaasDir, BPSaasDir, CADSaasDir) if err != nil { return err @@ -58,7 +58,7 @@ func servicePromotion(appInterface git.AppInterface, serviceName, gitHash string return fmt.Errorf("failed to read SAAS file: %v", err) } - currentGitHash, serviceRepo, err := git.GetCurrentGitHashFromAppInterface(serviceData, serviceName) + currentGitHash, serviceRepo, err := git.GetCurrentGitHashFromAppInterface(serviceData, serviceName, namespaceRef) if err != nil { return fmt.Errorf("failed to get current git hash or service repo: %v", err) }