Skip to content

Commit

Permalink
Merge pull request #610 from dustman9000/support-namespace-ref
Browse files Browse the repository at this point in the history
Support Passing Namespace Ref For SaaS Promotions
  • Loading branch information
openshift-merge-bot[bot] authored Sep 18, 2024
2 parents 47afd4c + 003d767 commit d7c9175
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
15 changes: 12 additions & 3 deletions cmd/promote/git/app_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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") {
Expand All @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/promote/saas/saas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions cmd/promote/saas/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit d7c9175

Please sign in to comment.