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

Created new flag --notifications-output-file to specify where to output notifications #181

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ The above command will:
| output | yaml | No | The output format, either yaml or json. |
| providers | all supported providers | Yes | Comma-separated list of providers. |
| kubeconfig | | No | The kubeconfig file to use when talking to the cluster. If the flag is not set, a set of standard locations can be searched for an existing kubeconfig file. |
| notifications-output-file | | No | The path to the file where notifications will be written to. If the flag is not present, notifications will be printed to stdout. |

## Conversion of Ingress resources to Gateway API

Expand Down
35 changes: 33 additions & 2 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type PrintRunner struct {

// Provider specific flags --<provider>-<flag>.
providerSpecificFlags map[string]*string

// notificationsOutputFile contains the path to the output file for notifications.
notificationsOutputFile string
}

// PrintGatewayAPIObjects performs necessary steps to digest and print
Expand All @@ -92,8 +95,16 @@ func (pr *PrintRunner) PrintGatewayAPIObjects(cmd *cobra.Command, _ []string) er
return err
}

for _, table := range notificationTablesMap {
fmt.Println(table)
if pr.notificationsOutputFile != "" {
err = pr.writeNotificationsToFile(notificationTablesMap)
if err != nil {
return fmt.Errorf("failed to write notifications to file: %w", err)
}
} else {
// If no file is specified, print notifications to stdout
for _, table := range notificationTablesMap {
fmt.Println(table)
}
}

pr.outputResult(gatewayResources)
Expand Down Expand Up @@ -307,6 +318,9 @@ if specified with --namespace.`)
cmd.Flags().StringSliceVar(&pr.providers, "providers", []string{},
fmt.Sprintf("If present, the tool will try to convert only resources related to the specified providers, supported values are %v.", i2gw.GetSupportedProviders()))

cmd.Flags().StringVar(&pr.notificationsOutputFile, "notifications-output-file", "",
"Path to the file where notifications will be written. If not specified, notifications will be printed to stdout.")

pr.providerSpecificFlags = make(map[string]*string)
for provider, flags := range i2gw.GetProviderSpecificFlagDefinitions() {
for _, flag := range flags {
Expand Down Expand Up @@ -365,3 +379,20 @@ func PrintUnstructuredAsYaml(obj *unstructured.Unstructured) error {

return nil
}

// writeNotificationsToFile writes the notification tables to the specified file
func (pr *PrintRunner) writeNotificationsToFile(notificationTablesMap map[string]string) error {
file, err := os.Create(pr.notificationsOutputFile)
if err != nil {
return err
}
defer file.Close()

for _, table := range notificationTablesMap {
_, err := file.WriteString(table + "\n")
if err != nil {
return err
}
}
return nil
}