-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package validation | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"github.com/apache/dubbo-kubernetes/operator/pkg/apis" | ||
"github.com/apache/dubbo-kubernetes/operator/pkg/values" | ||
) | ||
|
||
func ParseAndValidateDubboOperator(dopMap values.Map) (Warnings, util.Errors) { | ||
Check failure on line 10 in operator/cmd/validation/validation.go GitHub Actions / Go Test
|
||
dop := &apis.DubboOperator{} | ||
dec := json.NewDecoder(bytes.NewBufferString(dopMap.JSON())) | ||
dec.DisallowUnknownFields() | ||
if err := dec.Decode(dop); err != nil { | ||
return nil, util.NewErrs(fmt.Errorf("could not unmarshal: %v", err)) | ||
Check failure on line 15 in operator/cmd/validation/validation.go GitHub Actions / Go Test
|
||
} | ||
var warnings Warnings | ||
var errors util.Errors | ||
vw, ve := validateValues(dop) | ||
warnings = util.AppendErrs(warnings, vw) | ||
errors = util.AppendErrs(errors, ve) | ||
errors = util.AppendErr(errors, validateComponentNames(dop.Spec.Components)) | ||
return warnings, errors | ||
} | ||
|
||
func validateValues(raw *apis.DubboOperator) (Warnings, util.Errors) { | ||
v := &apis.Values{} | ||
if err := yaml.Unmarshal(raw.Spec.Values, v); err != nil { | ||
return nil, util.NewErrs(fmt.Errorf("could not unmarshal: %v", err)) | ||
} | ||
return nil, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,65 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
"github.com/apache/dubbo-kubernetes/operator/manifest" | ||
"github.com/apache/dubbo-kubernetes/operator/pkg/util/clog" | ||
"github.com/apache/dubbo-kubernetes/operator/pkg/values" | ||
"io" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func () { | ||
|
||
} | ||
func MergeInputs(filenames []string, flags []string) ([]values.Map, error) { | ||
ConfigBase, err := values.MapFromJSON([]byte(`{ | ||
"apiVersion": "install.dubbo.io/v1alpha1", | ||
"kind": "DubboOperator", | ||
"metadata": {}, | ||
"spec": {} | ||
}`)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for i, fn := range filenames { | ||
var b []byte | ||
var err error | ||
if fn == "-" { | ||
if i != len(filenames)-1 { | ||
return nil, fmt.Errorf("stdin is only allowed as the last filename") | ||
} | ||
b, err = io.ReadAll(os.Stdin) | ||
} else { | ||
b, err = os.ReadFile(strings.TrimSpace(fn)) | ||
} | ||
} | ||
return nil, nil | ||
} | ||
func checkDops(s string) error { | ||
mfs, err := manifest.ParseMultiple(s) | ||
if err != nil { | ||
return fmt.Errorf("unable to parse file: %v", err) | ||
} | ||
if len(mfs) > 1 { | ||
return fmt.Errorf("") | ||
} | ||
return nil | ||
} | ||
func GenerateManifest(files []string, setFlags []string, logger clog.Logger) ([]manifest.ManifestSet, values.Map, error) { | ||
merged, err := MergeInputs(files, setFlags) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("merge inputs: %v", err) | ||
} | ||
} | ||
|
||
func validateDubboOperator(dop values.Map, logger clog.Logger) error { | ||
warnings, errs := validation.ParseAndValidateDubboOperator(dop) | ||
if err := errs.ToError(); err != nil { | ||
return err | ||
} | ||
if logger != nil { | ||
for _, w := range warnings { | ||
logger.LogAndErrorf("%s %v", "❗", w) | ||
} | ||
} | ||
return nil | ||
} |