1+ // Package app implements Cloud Foundry App resource export functionality.
2+ // It fetches CF applications from the API, converts them to Crossplane App resources,
3+ // and handles filtering by organization and space.
14package app
25
36import (
@@ -32,15 +35,19 @@ func init() {
3235 resources .RegisterKind (app {})
3336}
3437
38+ // res wraps a Cloud Foundry App with comment metadata for YAML export.
3539type res struct {
3640 * resource.App
3741 * yaml.ResourceWithComment
3842}
3943
44+ // GetGUID returns the Cloud Foundry GUID of the application.
4045func (r * res ) GetGUID () string {
4146 return r .GUID
4247}
4348
49+ // GetName returns the sanitized name of the application suitable for Kubernetes resources.
50+ // If sanitization fails, a warning comment is added to the resource.
4451func (r * res ) GetName () string {
4552 name := r .Name
4653 names := parsan .ParseAndSanitize (name , parsan .RFC1035LowerSubdomain )
@@ -52,18 +59,23 @@ func (r *res) GetName() string {
5259 return name
5360}
5461
62+ // app implements the resources.Kind interface for CF App export.
5563type app struct {}
5664
5765var _ resources.Kind = app {}
5866
67+ // Param returns the configuration parameter for filtering apps during export.
5968func (a app ) Param () configparam.ConfigParam {
6069 return param
6170}
6271
72+ // KindName returns the name of this resource kind ("app").
6373func (a app ) KindName () string {
6474 return param .GetName ()
6575}
6676
77+ // Export fetches CF applications, converts them to Crossplane resources, and emits them via the event handler.
78+ // It filters apps by organization/space and processes each matching application.
6779func (a app ) Export (ctx context.Context , cfClient * client.Client , evHandler export.EventHandler , resolveReferences bool ) error {
6880 apps , err := Get (ctx , cfClient )
6981 if err != nil {
@@ -83,6 +95,7 @@ func (a app) Export(ctx context.Context, cfClient *client.Client, evHandler expo
8395 return nil
8496}
8597
98+ // getAllNamesFn returns a function that fetches all app names for the given org/space GUIDs.
8699func getAllNamesFn (ctx context.Context , cfClient * client.Client , orgGuids , spaceGuids []string ) func () ([]string , error ) {
87100 return func () ([]string , error ) {
88101 resources , err := getAll (ctx , cfClient , orgGuids , spaceGuids , []string {})
@@ -97,6 +110,8 @@ func getAllNamesFn(ctx context.Context, cfClient *client.Client, orgGuids, space
97110 }
98111}
99112
113+ // Get returns all CF applications matching the configured filter criteria.
114+ // Results are cached for subsequent calls. It prompts for app selection if none are specified.
100115func Get (ctx context.Context , cfClient * client.Client ) (mkcontainer.TypedContainer [* res ], error ) {
101116 if c != nil {
102117 return c , nil
@@ -143,6 +158,8 @@ func Get(ctx context.Context, cfClient *client.Client) (mkcontainer.TypedContain
143158 return c , nil
144159}
145160
161+ // getAll retrieves applications from the CF API and filters them by the provided name patterns.
162+ // Supports regex matching for app names. If appNames is empty, matches all applications.
146163func getAll (ctx context.Context , cfClient * client.Client , orgGuids , spaceGuids , appNames []string ) ([]* res , error ) {
147164 var nameRxs []* regexp.Regexp
148165
0 commit comments