Skip to content

Commit 4c563f7

Browse files
docs(exporter): add documentation comments to app export package
1 parent c26f9a7 commit 4c563f7

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

cmd/exporter/cf/app/app.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
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.
14
package app
25

36
import (
@@ -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.
3539
type res struct {
3640
*resource.App
3741
*yaml.ResourceWithComment
3842
}
3943

44+
// GetGUID returns the Cloud Foundry GUID of the application.
4045
func (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.
4451
func (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.
5563
type app struct{}
5664

5765
var _ resources.Kind = app{}
5866

67+
// Param returns the configuration parameter for filtering apps during export.
5968
func (a app) Param() configparam.ConfigParam {
6069
return param
6170
}
6271

72+
// KindName returns the name of this resource kind ("app").
6373
func (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.
6779
func (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.
8699
func 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.
100115
func 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.
146163
func getAll(ctx context.Context, cfClient *client.Client, orgGuids, spaceGuids, appNames []string) ([]*res, error) {
147164
var nameRxs []*regexp.Regexp
148165

cmd/exporter/cf/app/convert.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package app implements Cloud Foundry App resource export functionality.
12
package app
23

34
import (
@@ -18,6 +19,8 @@ import (
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920
)
2021

22+
// convertDockerField converts Docker configuration from CF manifest to Crossplane DockerConfiguration.
23+
// Generates a Secret for Docker credentials if username is provided. Password is set to "TODO" placeholder.
2124
func convertDockerField(app *res, managedApp *v1alpha1.App, appManifest *operation.AppManifest, evHandler export.EventHandler) error {
2225
docker := appManifest.Docker
2326

@@ -51,6 +54,8 @@ func convertDockerField(app *res, managedApp *v1alpha1.App, appManifest *operati
5154
return nil
5255
}
5356

57+
// convertProcessesField converts CF application processes to Crossplane ProcessConfiguration.
58+
// Handles all process types including web and worker processes with health checks.
5459
func convertProcessesField(managedApp *v1alpha1.App, appManifest *operation.AppManifest) {
5560
if appManifest.Processes == nil {
5661
return
@@ -78,6 +83,9 @@ func convertProcessesField(managedApp *v1alpha1.App, appManifest *operation.AppM
7883
}
7984
}
8085

86+
// convertAppResource converts a CF application to a Crossplane App resource with manifest data.
87+
// Fetches the app manifest, converts Docker config and processes, and optionally resolves space references.
88+
// Returns a ResourceWithComment containing the converted App and any warning comments.
8189
func convertAppResource(ctx context.Context, cfClient *client.Client, app *res, evHandler export.EventHandler, resolveReferences bool) *yaml.ResourceWithComment {
8290
slog.Debug("converting app", "name", app.Name)
8391

cmd/exporter/cf/app/manifest.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package app implements Cloud Foundry App resource export functionality.
12
package app
23

34
import (
@@ -27,6 +28,8 @@ import (
2728
// Applications []application `json:"applications"`
2829
// }
2930

31+
// getManifest fetches the application manifest from Cloud Foundry API for the given app GUID.
32+
// Returns the parsed manifest containing all application configurations.
3033
func getManifest(ctx context.Context, cfClient *client.Client, appGUID string) (*operation.Manifest, error) {
3134
m := &operation.Manifest{}
3235
stringManifest, err := cfClient.Manifests.Generate(ctx, appGUID)
@@ -40,6 +43,8 @@ func getManifest(ctx context.Context, cfClient *client.Client, appGUID string) (
4043
return m, err
4144
}
4245

46+
// getAppManifest retrieves the first application manifest from the CF API response.
47+
// Returns nil if no applications are found in the manifest.
4348
func getAppManifest(ctx context.Context, cfClient *client.Client, appGUID string) (*operation.AppManifest, error) {
4449
m, err := getManifest(ctx, cfClient, appGUID)
4550
if err != nil {

cmd/exporter/cf/app/secret.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package app implements Cloud Foundry App resource export functionality.
12
package app
23

34
import (
@@ -6,6 +7,9 @@ import (
67
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
78
)
89

10+
// generateDockerCredentialSecret creates a Kubernetes Secret for Docker registry credentials.
11+
// The password field is set to "TODO" as a placeholder since the actual password cannot be exported.
12+
// The secret includes a comment reminding users to manually fill in the password.
913
func generateDockerCredentialSecret(name, username string) *yaml.ResourceWithComment {
1014
s := &v1.Secret{
1115
TypeMeta: metav1.TypeMeta{

0 commit comments

Comments
 (0)