-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
- Loading branch information
1 parent
133fbaf
commit 4e62288
Showing
12 changed files
with
83 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/jinzhu/copier" | ||
) | ||
|
||
type Value = interface{} | ||
|
||
// +k8s:deepcopy-gen=false | ||
type Any struct { | ||
// TODO: this is needed to workaround a bug in api machinery code | ||
// https://kubernetes.slack.com/archives/C0EG7JC6T/p1696331287543159 | ||
// +kubebuilder:pruning:PreserveUnknownFields | ||
// +kubebuilder:validation:Schemaless | ||
Value `json:",inline"` | ||
Value interface{} `json:",inline"` | ||
} | ||
|
||
func (in *Any) DeepCopyInto(out *Any) { | ||
if err := copier.Copy(out, in); err != nil { | ||
panic("deep copy failed") | ||
} | ||
} | ||
|
||
func (a *Any) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(a.Value) | ||
} | ||
|
||
func (a *Any) UnmarshalJSON(data []byte) error { | ||
var v interface{} | ||
err := json.Unmarshal(data, &v) | ||
if err != nil { | ||
return err | ||
} | ||
a.Value = v | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"github.com/jinzhu/copier" | ||
) | ||
// // Variable defines an arbitrary JMESPath context variable that can be defined inline. | ||
// // +k8s:deepcopy-gen=false | ||
// type Variable struct { | ||
// // Value is any arbitrary object. | ||
// // +kubebuilder:pruning:PreserveUnknownFields | ||
// // +kubebuilder:validation:Schemaless | ||
// Value interface{} `json:"value,omitempty"` | ||
// } | ||
|
||
// Variable defines an arbitrary JMESPath context variable that can be defined inline. | ||
// +k8s:deepcopy-gen=false | ||
type Variable struct { | ||
// Value is any arbitrary object. | ||
// +kubebuilder:pruning:PreserveUnknownFields | ||
// +kubebuilder:validation:Schemaless | ||
Value interface{} `json:"value,omitempty"` | ||
} | ||
|
||
func (in *Variable) DeepCopy() *Variable { | ||
if in == nil { | ||
return nil | ||
} | ||
out := &Variable{} | ||
if err := copier.Copy(out, in); err != nil { | ||
panic("deep copy failed") | ||
} | ||
return out | ||
} | ||
// func (in *Variable) DeepCopy() *Variable { | ||
// if in == nil { | ||
// return nil | ||
// } | ||
// out := &Variable{} | ||
// if err := copier.Copy(out, in); err != nil { | ||
// panic("deep copy failed") | ||
// } | ||
// return out | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
// import ( | ||
// "reflect" | ||
// "testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
// "github.com/stretchr/testify/assert" | ||
// ) | ||
|
||
func TestVariable_DeepCopy(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in *Variable | ||
}{{ | ||
name: "nil", | ||
in: &Variable{nil}, | ||
}, { | ||
name: "nil", | ||
in: nil, | ||
}, { | ||
name: "int", | ||
in: &Variable{42}, | ||
}, { | ||
name: "string", | ||
in: &Variable{"foo"}, | ||
}, { | ||
name: "slice", | ||
in: &Variable{[]interface{}{42, "string"}}, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.in.DeepCopy(); !reflect.DeepEqual(got, tt.in) { | ||
t.Errorf("Variable.DeepCopy() = %v, want %v", got, tt.in) | ||
} else if tt.in != nil { | ||
assert.False(t, got == tt.in) | ||
} | ||
}) | ||
} | ||
} | ||
// func TestVariable_DeepCopy(t *testing.T) { | ||
// tests := []struct { | ||
// name string | ||
// in *Variable | ||
// }{{ | ||
// name: "nil", | ||
// in: &Variable{nil}, | ||
// }, { | ||
// name: "nil", | ||
// in: nil, | ||
// }, { | ||
// name: "int", | ||
// in: &Variable{42}, | ||
// }, { | ||
// name: "string", | ||
// in: &Variable{"foo"}, | ||
// }, { | ||
// name: "slice", | ||
// in: &Variable{[]interface{}{42, "string"}}, | ||
// }} | ||
// for _, tt := range tests { | ||
// t.Run(tt.name, func(t *testing.T) { | ||
// if got := tt.in.DeepCopy(); !reflect.DeepEqual(got, tt.in) { | ||
// t.Errorf("Variable.DeepCopy() = %v, want %v", got, tt.in) | ||
// } else if tt.in != nil { | ||
// assert.False(t, got == tt.in) | ||
// } | ||
// }) | ||
// } | ||
// } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters