Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Use a struct for GenericMaps
Browse files Browse the repository at this point in the history
Switch GenericMap from a named `map[string]interface{}` type
to a struct with a Data field. This allows us to override the openapi
spec once, at the type level, instead of retroactively at runtime for
each new field of type GenericMap added to our API structs.

This prevents the "managedFields" log that occurs when we forget to add
new fields to the OpenAPI modification logic.

Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
  • Loading branch information
njhale committed Aug 25, 2023
1 parent 37cd895 commit 9a8f556
Show file tree
Hide file tree
Showing 36 changed files with 346 additions and 308 deletions.
34 changes: 21 additions & 13 deletions integration/client/apps/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ func TestAppUpdate(t *testing.T) {
Service: "other-service2",
},
},
DeployArgs: map[string]any{
"param1": "val1",
"param2": "val2",
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"param1": "val1",
"param2": "val2",
},
},
})
if err != nil {
Expand Down Expand Up @@ -227,9 +229,11 @@ func TestAppUpdate(t *testing.T) {
Service: "other-service3",
},
},
DeployArgs: map[string]any{
"param2": "val3",
"param3": "val3",
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"param2": "val3",
"param3": "val3",
},
},
})
if err != nil {
Expand Down Expand Up @@ -302,10 +306,12 @@ func TestAppUpdate(t *testing.T) {
},
}, thirdApp.Spec.Links)

assert.Equal(t, v1.GenericMap{
"param1": "val1",
"param2": "val3",
"param3": "val3",
assert.Equal(t, &v1.GenericMap{
Data: map[string]any{
"param1": "val1",
"param2": "val3",
"param3": "val3",
},
}, thirdApp.Spec.DeployArgs)

assert.Equal(t, imageID2, thirdApp.Spec.Image)
Expand Down Expand Up @@ -447,8 +453,10 @@ func TestAppRun(t *testing.T) {
Target: "secretRequest",
},
},
DeployArgs: map[string]any{
"key": "value",
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"key": "value",
},
},
PublishMode: v1.PublishModeAll,
})
Expand All @@ -461,7 +469,7 @@ func TestAppRun(t *testing.T) {
assert.Equal(t, v1.PublishModeAll, app.Spec.PublishMode)
assert.Equal(t, "volume", app.Spec.Volumes[0].Volume)
assert.Equal(t, "secret", app.Spec.Secrets[0].Secret)
assert.Equal(t, "value", app.Spec.DeployArgs["key"])
assert.Equal(t, "value", app.Spec.DeployArgs.Data["key"])
}

func TestAppRunImageVariations(t *testing.T) {
Expand Down
12 changes: 8 additions & 4 deletions integration/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,10 @@ func TestDeployParam(t *testing.T) {
},
Spec: v1.AppInstanceSpec{
Image: image.ID,
DeployArgs: map[string]any{
"someInt": 5,
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"someInt": 5,
},
},
},
})
Expand Down Expand Up @@ -1470,8 +1472,10 @@ func TestCrossProjectNetworkConnection(t *testing.T) {
// run curl to test the connection
app, err := check.client.AppRun(ctx, check.imageID, &client.AppRunOptions{
Name: check.name,
DeployArgs: map[string]any{
"address": check.podIP,
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"address": check.podIP,
},
},
})
if err != nil {
Expand Down
18 changes: 12 additions & 6 deletions integration/secrets/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ func TestEncryptionEndToEnd(t *testing.T) {
}

app, err := c1.AppRun(context.Background(), image.ID, &client.AppRunOptions{
DeployArgs: map[string]any{
"encdata": output,
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"encdata": output,
},
},
})
if err != nil {
Expand Down Expand Up @@ -201,8 +203,10 @@ func TestNamespacedDecryption(t *testing.T) {
}

app, err := c2.AppRun(context.Background(), image.ID, &client.AppRunOptions{
DeployArgs: map[string]any{
"encdata": encdata,
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"encdata": encdata,
},
},
})
if err != nil {
Expand Down Expand Up @@ -237,8 +241,10 @@ func TestMultiKeyDecryptionEndToEnd(t *testing.T) {
}

app, err := c1.AppRun(context.Background(), image.ID, &client.AppRunOptions{
DeployArgs: map[string]any{
"encdata": encdata,
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"encdata": encdata,
},
},
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/api.acorn.io/v1/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ const (
EventSeverityError = internalv1.EventSeverityError
)

func Mapify(v any) (internalv1.GenericMap, error) {
return internalv1.Mapify(v)
func Mapify(data any) (internalv1.GenericMap, error) {
return internalv1.Mapify(data)
}
12 changes: 6 additions & 6 deletions pkg/apis/api.acorn.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ type ImageDetails struct {
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// Input Params
ImageName string `json:"imageName,omitempty"`
NestedDigest string `json:"nestedDigest,omitempty"`
DeployArgs v1.GenericMap `json:"deployArgs,omitempty"`
Profiles []string `json:"profiles,omitempty"`
Auth *RegistryAuth `json:"auth,omitempty"`
IncludeNested bool `json:"includeNested,omitempty"`
ImageName string `json:"imageName,omitempty"`
NestedDigest string `json:"nestedDigest,omitempty"`
DeployArgs *v1.GenericMap `json:"deployArgs,omitempty"`
Profiles []string `json:"profiles,omitempty"`
Auth *RegistryAuth `json:"auth,omitempty"`
IncludeNested bool `json:"includeNested,omitempty"`
// NoDefaultRegistry - if true, do not assume a default registry on the image if none is specified
NoDefaultRegistry bool `json:"noDefaultRegistry,omitempty"`

Expand Down
7 changes: 5 additions & 2 deletions pkg/apis/api.acorn.io/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/apis/internal.acorn.io/v1/appimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ type AppImage struct {
// ImageInstance.Name
ID string `json:"id,omitempty"`
// Name is the image name requested by the user of any format
Name string `json:"name,omitempty"`
Digest string `json:"digest,omitempty"`
Acornfile string `json:"acornfile,omitempty"`
ImageData ImagesData `json:"imageData,omitempty"`
BuildArgs GenericMap `json:"buildArgs,omitempty"`
VCS VCS `json:"vcs,omitempty"`
Name string `json:"name,omitempty"`
Digest string `json:"digest,omitempty"`
Acornfile string `json:"acornfile,omitempty"`
ImageData ImagesData `json:"imageData,omitempty"`
BuildArgs *GenericMap `json:"buildArgs,omitempty"`
VCS VCS `json:"vcs,omitempty"`
}

type VCS struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/internal.acorn.io/v1/appinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type AppInstanceSpec struct {
TargetNamespace string `json:"targetNamespace,omitempty"`
Links []ServiceBinding `json:"services,omitempty"`
Publish []PortBinding `json:"ports,omitempty"`
DeployArgs GenericMap `json:"deployArgs,omitempty"`
DeployArgs *GenericMap `json:"deployArgs,omitempty"`
Permissions []Permissions `json:"permissions,omitempty"`
ImageGrantedPermissions []Permissions `json:"imageGrantedPermissions,omitempty"`
AutoUpgrade *bool `json:"autoUpgrade,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/internal.acorn.io/v1/appspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ type Acorn struct {
Image string `json:"image,omitempty"`
Build *AcornBuild `json:"build,omitempty"`
Profiles []string `json:"profiles,omitempty"`
DeployArgs GenericMap `json:"deployArgs,omitempty"`
DeployArgs *GenericMap `json:"deployArgs,omitempty"`
Publish PortBindings `json:"publish,omitempty"`
PublishMode PublishMode `json:"publishMode,omitempty"`
Environment NameValues `json:"environment,omitempty"`
Expand All @@ -749,7 +749,7 @@ type Secret struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Params GenericMap `json:"params,omitempty"`
Params *GenericMap `json:"params,omitempty"`
Data map[string]string `json:"data,omitempty"`
}

Expand Down Expand Up @@ -791,11 +791,11 @@ type Service struct {
Address string `json:"address,omitempty"`
Ports Ports `json:"ports,omitempty"`
Container string `json:"container,omitempty"`
Data GenericMap `json:"data,omitempty"`
Data *GenericMap `json:"data,omitempty"`
Generated *GeneratedService `json:"generated,omitempty"`
Image string `json:"image,omitempty"`
Build *AcornBuild `json:"build,omitempty"`
ServiceArgs GenericMap `json:"serviceArgs,omitempty"`
ServiceArgs *GenericMap `json:"serviceArgs,omitempty"`
Environment NameValues `json:"environment,omitempty"`
Secrets SecretBindings `json:"secrets,omitempty"`
Links ServiceBindings `json:"links,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/internal.acorn.io/v1/appstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type ServiceStatus struct {
CommonStatus `json:",inline"`
Default bool `json:"default,omitempty"`
Ports Ports `json:"ports,omitempty"`
Data GenericMap `json:"data,omitempty"`
Data *GenericMap `json:"data,omitempty"`
Consumer *ServiceConsumer `json:"consumer,omitempty"`
Secrets []string `json:"secrets,omitempty"`
Address string `json:"address,omitempty"`
Expand Down

0 comments on commit 9a8f556

Please sign in to comment.