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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
njhale committed Aug 22, 2023
1 parent 0b00491 commit 7de55c1
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 116 deletions.
6 changes: 3 additions & 3 deletions integration/client/apps/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestAppUpdate(t *testing.T) {
Service: "other-service2",
},
},
DeployArgs: v1.GenericMap{
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"param1": "val1",
"param2": "val2",
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestAppUpdate(t *testing.T) {
Service: "other-service3",
},
},
DeployArgs: v1.GenericMap{
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"param2": "val3",
"param3": "val3",
Expand Down Expand Up @@ -453,7 +453,7 @@ func TestAppRun(t *testing.T) {
Target: "secretRequest",
},
},
DeployArgs: v1.GenericMap{
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"key": "value",
},
Expand Down
4 changes: 2 additions & 2 deletions integration/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ func TestDeployParam(t *testing.T) {
},
Spec: v1.AppInstanceSpec{
Image: image.ID,
DeployArgs: v1.GenericMap{
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"someInt": 5,
},
Expand Down Expand Up @@ -1472,7 +1472,7 @@ 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: v1.GenericMap{
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"address": check.podIP,
},
Expand Down
6 changes: 3 additions & 3 deletions integration/secrets/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestEncryptionEndToEnd(t *testing.T) {
}

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

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

app, err := c1.AppRun(context.Background(), image.ID, &client.AppRunOptions{
DeployArgs: v1.GenericMap{
DeployArgs: &v1.GenericMap{
Data: map[string]any{
"encdata": encdata,
},
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 NewGenericMap(data any) (internalv1.GenericMap, error) {
return internalv1.NewGenericMap(data)
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
5 changes: 4 additions & 1 deletion 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
49 changes: 35 additions & 14 deletions pkg/apis/internal.acorn.io/v1/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,28 @@ func (_ GenericMap) OpenAPIDefinition() common.OpenAPIDefinition {
}
}

func (in GenericMap) Set(k string, v any) GenericMap {
if in.Data == nil {
in.Data = map[string]any{}
func (g *GenericMap) Set(k string, v any) *GenericMap {
if g == nil {
g = new(GenericMap)
}

if g.Data == nil {
g.Data = map[string]any{}
}

g.Data[k] = v

return g
}

func (g *GenericMap) Get(k string) (v any, ok bool) {
if g == nil {
return
}
in.Data[k] = v

return in
v, ok = g.Data[k]

return
}

func (g *GenericMap) UnmarshalJSON(data []byte) error {
Expand All @@ -56,17 +71,25 @@ func (g *GenericMap) UnmarshalJSON(data []byte) error {
return fmt.Errorf("%T: Failed to translate object: %w", g, err)
}

g.Data = d
if len(d) > 0 {
// Consumers expect empty generic maps to have a nil Data field
g.Data = d
}

return nil
}

// MarshalJSON may get called on pointers or values, so implement MarshalJSON on value.
// http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
func (g GenericMap) MarshalJSON() ([]byte, error) {
if g.Data == nil {
return []byte("null"), nil
}
//if g.Data == nil {
// return nil, nil
//}

// Encode unset/nil objects as JSON's "null"
// if g.Data == nil {
// return []byte("null"), nil
// }

return json.Marshal(g.Data)
}
Expand Down Expand Up @@ -97,20 +120,18 @@ func translateObject(data interface{}) (ret interface{}, err error) {

func (in *GenericMap) DeepCopyInto(out *GenericMap) {
var err error
if *out, err = NewGenericMap(in.Data); err != nil {
if *out, err = Mapify(in.Data); err != nil {
logrus.WithError(err).Errorf("failed to deep copy into [%T]", out)
}
}

func NewGenericMap(data any) (GenericMap, error) {
func Mapify(data any) (GenericMap, error) {
marshaled, err := json.Marshal(data)
if err != nil {
return GenericMap{}, err
}

gm := &GenericMap{
Data: map[string]any{},
}
gm := &GenericMap{}
if err := gm.UnmarshalJSON(marshaled); err != nil {
return GenericMap{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/internal.acorn.io/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type ServiceInstanceSpec struct {
Job string `json:"job,omitempty"`
ContainerLabels map[string]string `json:"containerLabels,omitempty"`
Secrets []string `json:"secrets,omitempty"`
Data GenericMap `json:"data,omitempty"`
Data *GenericMap `json:"data,omitempty"`
Consumer *ServiceConsumer `json:"consumer,omitempty"`

// Fields from app
Expand Down
40 changes: 32 additions & 8 deletions pkg/apis/internal.acorn.io/v1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/appdefinition/appdefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func AppImageFromTar(reader io.Reader) (*v1.AppImage, *DataFiles, error) {
return nil, nil, err
}
case BuildDataFile:
result.BuildArgs = v1.GenericMap{Data: map[string]any{}}
result.BuildArgs = &v1.GenericMap{Data: map[string]any{}}
err := json.NewDecoder(tar).Decode(&result.BuildArgs)
if err != nil {
return nil, nil, err
Expand Down

0 comments on commit 7de55c1

Please sign in to comment.