-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add support to keda scaledobject v1alpha1 (#711)
Co-authored-by: Jonathan Henrique Medeiros <[email protected]> Co-authored-by: Tomasz Janiszewski <[email protected]>
- Loading branch information
1 parent
cd1e926
commit 39d132c
Showing
10 changed files
with
440 additions
and
221 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
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,37 @@ | ||
package mocks | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
kedaV1Alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" | ||
"github.com/stretchr/testify/require" | ||
"golang.stackrox.io/kube-linter/pkg/objectkinds" | ||
|
||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// AddMockScaledObject adds a mock ScaledObject to LintContext | ||
func (l *MockLintContext) AddMockScaledObject(t *testing.T, name, version string) { | ||
require.NotEmpty(t, name) | ||
switch version { | ||
case "v1alpha1": | ||
l.objects[name] = &kedaV1Alpha1.ScaledObject{ | ||
TypeMeta: metaV1.TypeMeta{ | ||
Kind: objectkinds.ScaledObject, | ||
APIVersion: objectkinds.GetScaledObjectAPIVersion(version), | ||
}, | ||
ObjectMeta: metaV1.ObjectMeta{Name: name}, | ||
Spec: kedaV1Alpha1.ScaledObjectSpec{}, | ||
} | ||
default: | ||
require.FailNow(t, fmt.Sprintf("Unknown scaled object version %s", version)) | ||
} | ||
} | ||
|
||
// ModifyScaledObjectV1Alpha1 modifies a given ScaledObject in the context via the passed function. | ||
func (l *MockLintContext) ModifyScaledObjectV1Alpha1(t *testing.T, name string, f func(hpa *kedaV1Alpha1.ScaledObject)) { | ||
r, ok := l.objects[name].(*kedaV1Alpha1.ScaledObject) | ||
require.True(t, ok) | ||
f(r) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package objectkinds | ||
|
||
import ( | ||
"fmt" | ||
|
||
kedaV1Alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
const ( | ||
// ScaledObject represents Kubernetes ScaledObject objects. Case sensitive. | ||
ScaledObject = "ScaledObject" | ||
) | ||
|
||
var ( | ||
ScaledObjectV1Alpha1 = kedaV1Alpha1.SchemeGroupVersion.WithKind(ScaledObject) | ||
) | ||
|
||
func isScaledObject(gvk schema.GroupVersionKind) bool { | ||
return gvk == ScaledObjectV1Alpha1 | ||
} | ||
|
||
func init() { | ||
RegisterObjectKind(ScaledObject, MatcherFunc(isScaledObject)) | ||
} | ||
|
||
// GetScaledObjectAPIVersion returns ScaledObject's APIVersion | ||
func GetScaledObjectAPIVersion(version string) string { | ||
return fmt.Sprintf("%s/%s", ScaledObjectV1Alpha1.Group, version) | ||
} |
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