Skip to content

Commit

Permalink
chore: fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Apr 15, 2024
1 parent bafa044 commit efc008e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 117 deletions.
12 changes: 6 additions & 6 deletions pkg/health/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/health/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down
61 changes: 0 additions & 61 deletions pkg/lua/custom_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
8 changes: 0 additions & 8 deletions pkg/lua/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 0 additions & 41 deletions pkg/lua/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package lua

import (
"encoding/json"
"regexp"

"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit efc008e

Please sign in to comment.