diff --git a/pkg/health/status.go b/pkg/health/status.go index e582b89..a7f000b 100644 --- a/pkg/health/status.go +++ b/pkg/health/status.go @@ -82,19 +82,19 @@ func GetGenericStatus(obj *unstructured.Unstructured) GenericStatus { type OnCondition struct { // When 2 conditions are true, which one takes precedence from a status/message perspective - Order int `yaml:"order:onempty" json:"order,omitempty"` + Order int `yaml:"order:omitempty" json:"order,omitempty"` // If the condition matches, mark ready - Ready bool `yaml:"ready" yaml:"ready,omitempty"` + Ready bool `json:"ready" yaml:"ready"` // If the condition matches, mark not ready - NotReady bool `yaml:"notReady" yaml:"notRead,omitempty"` + NotReady bool `json:"notReady" yaml:"notReady,omitempty"` // If the condition is true, use the conditions message - Message bool `yaml:"message" yaml:"message,omitempty"` - Health Health `yaml:"health,omitempty" yaml:"health,omitempty"` + Message bool `json:"message" yaml:"message"` + Health Health `json:"health,omitempty" yaml:"health,omitempty"` // Health to set if the condition is false - Status HealthStatusCode `yaml:"status,omitempty" yaml:"status,omitempty"` + Status HealthStatusCode `json:"status,omitempty" yaml:"status,omitempty"` } func (mapped *OnCondition) Apply(health *HealthStatus, c *metav1.Condition) { diff --git a/pkg/health/utils.go b/pkg/health/utils.go index 40877d8..f7830d6 100644 --- a/pkg/health/utils.go +++ b/pkg/health/utils.go @@ -36,7 +36,7 @@ type HealthStatus struct { // Message is a human-readable informational message describing the health status Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"` - order int `json:"-", yaml:"-"` + order int `json:"-" yaml:"-"` } func (hs *HealthStatus) AppendMessage(msg string, args ...interface{}) { diff --git a/pkg/lua/custom_actions_test.go b/pkg/lua/custom_actions_test.go index 9e82bf4..a1d29a1 100644 --- a/pkg/lua/custom_actions_test.go +++ b/pkg/lua/custom_actions_test.go @@ -13,67 +13,6 @@ import ( "sigs.k8s.io/yaml" ) -type testNormalizer struct{} - -func (t testNormalizer) Normalize(un *unstructured.Unstructured) error { - if un == nil { - return nil - } - switch un.GetKind() { - case "Job": - err := unstructured.SetNestedField(un.Object, map[string]interface{}{"name": "not sure why this works"}, "metadata") - if err != nil { - return fmt.Errorf("failed to normalize Job: %w", err) - } - } - switch un.GetKind() { - case "DaemonSet", "Deployment", "StatefulSet": - err := unstructured.SetNestedStringMap(un.Object, map[string]string{"kubectl.kubernetes.io/restartedAt": "0001-01-01T00:00:00Z"}, "spec", "template", "metadata", "annotations") - if err != nil { - return fmt.Errorf("failed to normalize %s: %w", un.GetKind(), err) - } - } - switch un.GetKind() { - case "Deployment": - err := unstructured.SetNestedField(un.Object, nil, "status") - if err != nil { - return fmt.Errorf("failed to normalize %s: %w", un.GetKind(), err) - } - err = unstructured.SetNestedField(un.Object, nil, "metadata", "creationTimestamp") - if err != nil { - return fmt.Errorf("failed to normalize %s: %w", un.GetKind(), err) - } - err = unstructured.SetNestedField(un.Object, nil, "metadata", "generation") - if err != nil { - return fmt.Errorf("failed to normalize %s: %w", un.GetKind(), err) - } - case "Rollout": - err := unstructured.SetNestedField(un.Object, nil, "spec", "restartAt") - if err != nil { - return fmt.Errorf("failed to normalize %s: %w", un.GetKind(), err) - } - case "ExternalSecret": - err := unstructured.SetNestedStringMap(un.Object, map[string]string{"force-sync": "0001-01-01T00:00:00Z"}, "metadata", "annotations") - if err != nil { - return fmt.Errorf("failed to normalize %s: %w", un.GetKind(), err) - } - case "Workflow": - err := unstructured.SetNestedField(un.Object, nil, "metadata", "resourceVersion") - if err != nil { - return fmt.Errorf("failed to normalize Rollout: %w", err) - } - err = unstructured.SetNestedField(un.Object, nil, "metadata", "uid") - if err != nil { - return fmt.Errorf("failed to normalize Rollout: %w", err) - } - err = unstructured.SetNestedField(un.Object, nil, "metadata", "annotations", "workflows.argoproj.io/scheduled-time") - if err != nil { - return fmt.Errorf("failed to normalize Rollout: %w", err) - } - } - return nil -} - type ActionTestStructure struct { DiscoveryTests []IndividualDiscoveryTest `yaml:"discoveryTests"` ActionTests []IndividualActionTest `yaml:"actionTests"` diff --git a/pkg/lua/lua.go b/pkg/lua/lua.go index cbb7658..45f2141 100644 --- a/pkg/lua/lua.go +++ b/pkg/lua/lua.go @@ -432,14 +432,6 @@ func (vm VM) getPredefinedLuaScripts(objKey string, scriptFile string) (string, return string(data), nil } -func isValidHealthStatusCode(statusCode health.HealthStatusCode) bool { - switch statusCode { - case health.HealthStatusUnknown, health.HealthStatusProgressing, health.HealthStatusSuspended, health.HealthStatusHealthy, health.HealthStatusDegraded, health.HealthStatusMissing: - return true - } - return false -} - // Took logic from the link below and added the int, int32, and int64 types since the value would have type int64 // while actually running in the controller and it was not reproducible through testing. // https://github.com/layeh/gopher-json/blob/97fed8db84274c421dbfffbb28ec859901556b97/json.go#L154 diff --git a/pkg/lua/resources.go b/pkg/lua/resources.go index f2f2a44..4fed7fd 100644 --- a/pkg/lua/resources.go +++ b/pkg/lua/resources.go @@ -2,7 +2,6 @@ package lua import ( "encoding/json" - "regexp" "gopkg.in/yaml.v2" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -121,46 +120,6 @@ type ResourceActionParam struct { Default string `json:"default,omitempty" protobuf:"bytes,4,opt,name=default"` } -// TODO: refactor to use rbacpolicy.ActionGet, rbacpolicy.ActionCreate, without import cycle -var validActions = map[string]bool{ - "get": true, - "create": true, - "update": true, - "delete": true, - "sync": true, - "override": true, - "*": true, -} - -var validActionPatterns = []*regexp.Regexp{ - regexp.MustCompile("action/.*"), -} - -func isValidAction(action string) bool { - if validActions[action] { - return true - } - for i := range validActionPatterns { - if validActionPatterns[i].MatchString(action) { - return true - } - } - return false -} - -// TODO: same as validActions, refacotor to use rbacpolicy.ResourceApplications etc. -var validResources = map[string]bool{ - "applications": true, - "repositories": true, - "clusters": true, - "exec": true, - "logs": true, -} - -func isValidResource(resource string) bool { - return validResources[resource] -} - // UnmarshalToUnstructured unmarshals a resource representation in JSON to unstructured data func UnmarshalToUnstructured(resource string) (*unstructured.Unstructured, error) { if resource == "" || resource == "null" {