-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCM-5027 | feat: Added KubeletConfigClient and mock to be shared betw…
…een Terraform and ROSA CLI
- Loading branch information
Showing
9 changed files
with
906 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
) | ||
|
||
//go:generate mockgen -source=clusterautoscaler_client.go -package=testing -destination=testing/mock_clusterautoscaler_client.go | ||
type ClusterAutoscalerClient interface { | ||
SingleClusterSubResource[v1.ClusterAutoscaler] | ||
} | ||
|
||
func NewClusterAutoscalerClient(collection *v1.ClustersClient) ClusterAutoscalerClient { | ||
return &SingleClusterSubResourceImpl[v1.ClusterAutoscaler]{ | ||
getFunc: func(ctx context.Context, clusterId string) (OcmResponseWithBody[v1.ClusterAutoscaler], error) { | ||
return collection.Cluster(clusterId).Autoscaler().Get().SendContext(ctx) | ||
}, | ||
updateFunc: func(ctx context.Context, clusterId string, instance *v1.ClusterAutoscaler) (OcmResponseWithBody[v1.ClusterAutoscaler], error) { | ||
return collection.Cluster(clusterId).Autoscaler().Update().Body(instance).SendContext(ctx) | ||
}, | ||
createFunc: func(ctx context.Context, clusterId string, instance *v1.ClusterAutoscaler) (OcmResponseWithBody[v1.ClusterAutoscaler], error) { | ||
return collection.Cluster(clusterId).Autoscaler().Post().Request(instance).SendContext(ctx) | ||
}, | ||
deleteFunc: func(ctx context.Context, clusterId string) (OcmResponse, error) { | ||
return collection.Cluster(clusterId).Autoscaler().Delete().SendContext(ctx) | ||
}, | ||
} | ||
} |
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,31 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
) | ||
|
||
// KubeletConfigClient wraps the OCM SDK to provide a more unit testable friendly way of | ||
// interacting with the OCM API | ||
// | ||
//go:generate mockgen -source=kubeletconfig_client.go -package=testing -destination=testing/mock_kubeletconfig_client.go | ||
type KubeletConfigClient interface { | ||
SingleClusterSubResource[v1.KubeletConfig] | ||
} | ||
|
||
func NewKubeletConfigClient(collection *v1.ClustersClient) KubeletConfigClient { | ||
return &SingleClusterSubResourceImpl[v1.KubeletConfig]{ | ||
getFunc: func(ctx context.Context, clusterId string) (OcmResponseWithBody[v1.KubeletConfig], error) { | ||
return collection.Cluster(clusterId).KubeletConfig().Get().SendContext(ctx) | ||
}, | ||
updateFunc: func(ctx context.Context, clusterId string, instance *v1.KubeletConfig) (OcmResponseWithBody[v1.KubeletConfig], error) { | ||
return collection.Cluster(clusterId).KubeletConfig().Update().Body(instance).SendContext(ctx) | ||
}, | ||
createFunc: func(ctx context.Context, clusterId string, instance *v1.KubeletConfig) (OcmResponseWithBody[v1.KubeletConfig], error) { | ||
return collection.Cluster(clusterId).KubeletConfig().Post().Body(instance).SendContext(ctx) | ||
}, | ||
deleteFunc: func(ctx context.Context, clusterId string) (OcmResponse, error) { | ||
return collection.Cluster(clusterId).KubeletConfig().Delete().SendContext(ctx) | ||
}, | ||
} | ||
} |
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,28 @@ | ||
package testing | ||
|
||
// Custom Gomega Matchers that make it easier to assert interactions with the OCM API | ||
|
||
import v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
|
||
type KubeletConfigMatcher struct { | ||
expected *v1.KubeletConfig | ||
} | ||
|
||
// KubeletConfigMatches returns a Matcher that asserts that the received KubeletConfig | ||
// matches the expected KubeletConfig | ||
func KubeletConfigMatches(expected *v1.KubeletConfig) KubeletConfigMatcher { | ||
return KubeletConfigMatcher{ | ||
expected: expected, | ||
} | ||
} | ||
|
||
func (k KubeletConfigMatcher) Matches(x interface{}) bool { | ||
if kubeletConfig, ok := x.(*v1.KubeletConfig); ok { | ||
return k.expected.PodPidsLimit() == kubeletConfig.PodPidsLimit() | ||
} | ||
return false | ||
} | ||
|
||
func (k KubeletConfigMatcher) String() string { | ||
return "Expected KubeletConfig Does Not Match" | ||
} |
113 changes: 113 additions & 0 deletions
113
pkg/ocm/client/testing/mock_clusterautoscaler_client.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 testing | ||
|
||
import v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
|
||
// MockKubeletConfig creates an empty KubeletConfig that can be used in tests. Tests can | ||
// mutate the KubeletConfig to their requirements via the variadic list of functions | ||
func MockKubeletConfig(modifyFn ...func(k *v1.KubeletConfig)) (*v1.KubeletConfig, error) { | ||
|
||
builder := &v1.KubeletConfigBuilder{} | ||
instance, err := builder.Build() | ||
return runModify(instance, err, modifyFn) | ||
} | ||
|
||
func MockClusterAutoscaler(modifyFn ...func(k *v1.ClusterAutoscaler)) (*v1.ClusterAutoscaler, error) { | ||
builder := v1.ClusterAutoscalerBuilder{} | ||
instance, err := builder.Build() | ||
return runModify(instance, err, modifyFn) | ||
} | ||
|
||
func runModify[T any](instance *T, err error, modifyFn []func(instance *T)) (*T, error) { | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, f := range modifyFn { | ||
f(instance) | ||
} | ||
|
||
return instance, nil | ||
} |
Oops, something went wrong.