Skip to content

Commit

Permalink
fixed rawextension and nil exception
Browse files Browse the repository at this point in the history
  • Loading branch information
pghildiyal committed Jul 4, 2023
1 parent e83ded4 commit e0268c6
Show file tree
Hide file tree
Showing 58 changed files with 221 additions and 850 deletions.
73 changes: 68 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,87 @@
module github.com/devtron-labs/silver-surfer

go 1.15
go 1.19

require (
github.com/fatih/color v1.10.0
github.com/getkin/kin-openapi v0.67.0
github.com/hashicorp/go-multierror v1.1.1
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/prometheus/common v0.4.0
github.com/spf13/cobra v0.0.0-20180820174524-ff0d02e85550
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.8.1 // indirect
github.com/tidwall/sjson v1.1.7
github.com/tomlazar/table v0.1.0
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v0.0.0-20180816142147-da425ebb7609
k8s.io/apimachinery v0.22.0
k8s.io/client-go v0.20.4
sigs.k8s.io/yaml v1.2.0
)

require (
cloud.google.com/go v0.54.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.1 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.5 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.0 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.2.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tidwall/gjson v1.8.1 // indirect
github.com/tidwall/match v1.0.3 // indirect
github.com/tidwall/pretty v1.1.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/api v0.20.4 // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
)
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,16 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
Expand Down Expand Up @@ -626,7 +623,6 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
20 changes: 10 additions & 10 deletions kubedd/kubedd.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func ValidateCluster(cluster *pkg.Cluster, conf *pkg.Config) ([]pkg.ValidationRe
}
serverVersion, err := cluster.ServerVersion()
if err != nil {
kLog.Error( err)
kLog.Error(err)
serverVersion = conf.TargetKubernetesVersion
}
resources, err := kubeC.GetKinds(serverVersion)
Expand Down Expand Up @@ -122,17 +122,18 @@ func ValidateCluster(cluster *pkg.Cluster, conf *pkg.Config) ([]pkg.ValidationRe
}
k8sObj = string(bt)
}
validationResult, err := kubeC.ValidateJson(k8sObj, conf.TargetKubernetesVersion)
if err != nil {
fmt.Printf("err: %v\n", err)
continue
if len(k8sObj) > 0 {
validationResult, err := kubeC.ValidateJson(k8sObj, conf.TargetKubernetesVersion)
if err != nil {
fmt.Printf("err: %v\n", err)
continue
}
//validationResult = isVersionSupported(validationResult, kubeC, conf)
validationResult = pkg.FilterValidationResults(validationResult, conf)
validationResults = append(validationResults, validationResult)
}
//validationResult = isVersionSupported(validationResult, kubeC, conf)
validationResult = pkg.FilterValidationResults(validationResult, conf)
validationResults = append(validationResults, validationResult)
}


return validationResults, nil
}

Expand Down Expand Up @@ -168,4 +169,3 @@ func ValidateCluster(cluster *pkg.Cluster, conf *pkg.Config) ([]pkg.ValidationRe
// return result
// }
//}

4 changes: 2 additions & 2 deletions kubedd/kubedd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
func TestValidateCluster(t *testing.T) {
cluster := pkg.NewCluster("", "")
config := pkg.NewDefaultConfig()
config.SelectKinds = []string{"ComponentStatus"}
config.TargetKubernetesVersion = "1.21"
config.SelectKinds = []string{"ControllerRevision"}
config.TargetKubernetesVersion = "1.27"
//config.SelectNamespaces = []string{"prod"}
type args struct {
cluster *pkg.Cluster
Expand Down
26 changes: 12 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ import (
)

var (
version = "0.1.0"
commit = "none"
date = "unknown"
directories = make([]string, 0)
ignoredPathPatterns = make([]string, 0)
kubeconfig = ""
kubecontext = ""
noColor = false
version = "0.1.0"
commit = "none"
date = "unknown"
directories = make([]string, 0)
ignoredPathPatterns = make([]string, 0)
kubeconfig = ""
kubecontext = ""
noColor = false
// forceColor tells kubedd to use colored output even if
// stdout is not a TTY
forceColor bool
Expand Down Expand Up @@ -97,9 +97,9 @@ var RootCmd = &cobra.Command{
// Assert that colors will definitely be used if requested
if forceColor {
color.NoColor = false
} else if noColor {
color.NoColor = true
}
} else if noColor {
color.NoColor = true
}

//if len(args) < 1 && len(directories) < 1 && len(kubeconfig) < 1 {
// log.Error(errors.New("at least one file or one directory or kubeconfig path should be passed as argument"))
Expand Down Expand Up @@ -192,8 +192,6 @@ func processCluster() bool {
return success
}



// hasErrors returns truthy if any of the provided results
// contain errors.
func hasErrors(res []pkg.ValidationResult) bool {
Expand Down Expand Up @@ -272,7 +270,7 @@ func init() {
RootCmd.Use = fmt.Sprintf("%s <file> [file...]", rootCmdName)
pkg.AddKubeaddFlags(RootCmd, config)
RootCmd.Flags().BoolVarP(&forceColor, "force-color", "", false, "Force colored output even if stdout is not a TTY")
RootCmd.Flags().BoolVarP(&noColor, "no-color", "", false, "Display results without color")
RootCmd.Flags().BoolVarP(&noColor, "no-color", "", false, "Display results without color")
RootCmd.SetVersionTemplate(`{{.Version}}`)
RootCmd.Flags().StringSliceVarP(&directories, "directories", "d", []string{}, "A comma-separated list of directories to recursively search for YAML documents")
RootCmd.Flags().StringSliceVarP(&ignoredPathPatterns, "ignored-path-patterns", "i", []string{}, "A comma-separated list of regular expressions specifying paths to ignore")
Expand Down
94 changes: 47 additions & 47 deletions pkg/Filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,69 @@ import (
func FilterValidationResults(result ValidationResult, conf *Config) ValidationResult {
//var vr []ValidationResult
//for _, result := range validationResults {
var errorsForLatest []*openapi3.SchemaError
var errorsForOriginal []*openapi3.SchemaError
for _, schemaError := range result.ErrorsForLatest {
if !conf.IgnoreNullErrors || strings.TrimSpace(schemaError.Reason) != "Value is not nullable" {
errorsForLatest = append(errorsForLatest, schemaError)
}
var errorsForLatest []*openapi3.SchemaError
var errorsForOriginal []*openapi3.SchemaError
for _, schemaError := range result.ErrorsForLatest {
if !conf.IgnoreNullErrors || strings.TrimSpace(schemaError.Reason) != "Value is not nullable" {
errorsForLatest = append(errorsForLatest, schemaError)
}
result.ErrorsForLatest = errorsForLatest
for _, schemaError := range result.ErrorsForOriginal {
if !conf.IgnoreNullErrors || strings.TrimSpace(schemaError.Reason) != "Value is not nullable" {
errorsForOriginal = append(errorsForOriginal, schemaError)
}
}
result.ErrorsForLatest = errorsForLatest
for _, schemaError := range result.ErrorsForOriginal {
if !conf.IgnoreNullErrors || strings.TrimSpace(schemaError.Reason) != "Value is not nullable" {
errorsForOriginal = append(errorsForOriginal, schemaError)
}
result.ErrorsForOriginal = errorsForOriginal
//vr = append(vr, result)
}
result.ErrorsForOriginal = errorsForOriginal
//vr = append(vr, result)
//}
return removeIgnoredKeys(result, conf)
}

func removeIgnoredKeys(result ValidationResult, conf *Config) ValidationResult {
//var out []ValidationResult
//for _, result := range results {
if len(result.DeprecationForOriginal) > 0 {
var depErr []*SchemaError
for _, schemaError := range result.DeprecationForOriginal {
key := strings.Join(schemaError.JSONPointer(), "/")
if !Contains(key, conf.IgnoreKeysFromDeprecation) {
depErr = append(depErr, schemaError)
}
if len(result.DeprecationForOriginal) > 0 {
var depErr []*SchemaError
for _, schemaError := range result.DeprecationForOriginal {
key := strings.Join(schemaError.JSONPointer(), "/")
if !Contains(key, conf.IgnoreKeysFromDeprecation) {
depErr = append(depErr, schemaError)
}
result.DeprecationForOriginal = depErr
}
if len(result.DeprecationForLatest) > 0 {
var depErr []*SchemaError
for _, schemaError := range result.DeprecationForLatest {
key := strings.Join(schemaError.JSONPointer(), "/")
if !Contains(key, conf.IgnoreKeysFromDeprecation) {
depErr = append(depErr, schemaError)
}
result.DeprecationForOriginal = depErr
}
if len(result.DeprecationForLatest) > 0 {
var depErr []*SchemaError
for _, schemaError := range result.DeprecationForLatest {
key := strings.Join(schemaError.JSONPointer(), "/")
if !Contains(key, conf.IgnoreKeysFromDeprecation) {
depErr = append(depErr, schemaError)
}
result.DeprecationForLatest = depErr
}
if len(result.ErrorsForOriginal) > 0 {
var valErr []*openapi3.SchemaError
for _, schemaError := range result.ErrorsForOriginal {
key := strings.Join(schemaError.JSONPointer(), "/")
if !Contains(key, conf.IgnoreKeysFromValidation) {
valErr = append(valErr, schemaError)
}
result.DeprecationForLatest = depErr
}
if len(result.ErrorsForOriginal) > 0 {
var valErr []*openapi3.SchemaError
for _, schemaError := range result.ErrorsForOriginal {
key := strings.Join(schemaError.JSONPointer(), "/")
if !Contains(key, conf.IgnoreKeysFromValidation) && !Contains(schemaError.Schema.Description, []string{"RawExtension*"}) {
valErr = append(valErr, schemaError)
}
result.ErrorsForOriginal = valErr
}
if len(result.ErrorsForLatest) > 0 {
var valErr []*openapi3.SchemaError
for _, schemaError := range result.ErrorsForLatest {
key := strings.Join(schemaError.JSONPointer(), "/")
if !Contains(key, conf.IgnoreKeysFromValidation) {
valErr = append(valErr, schemaError)
}
result.ErrorsForOriginal = valErr
}
if len(result.ErrorsForLatest) > 0 {
var valErr []*openapi3.SchemaError
for _, schemaError := range result.ErrorsForLatest {
key := strings.Join(schemaError.JSONPointer(), "/")
if !Contains(key, conf.IgnoreKeysFromValidation) {
valErr = append(valErr, schemaError)
}
result.ErrorsForLatest = valErr
}
//out = append(out, result)
result.ErrorsForLatest = valErr
}
//out = append(out, result)
//}
return result
}
}
Loading

0 comments on commit e0268c6

Please sign in to comment.