Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Factory from CloudProvider #460

Merged
merged 2 commits into from
Jun 17, 2021
Merged

Removed Factory from CloudProvider #460

merged 2 commits into from
Jun 17, 2021

Conversation

njtran
Copy link
Contributor

@njtran njtran commented Jun 16, 2021

Issue #, if available:
#441

Description of changes:
Removed concept of Factories from our codebase. This moves away from the programming concept of RAII that we used to make API calls to the cloud provider. We no longer need a factory to instantiate the API for us on a call.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@@ -73,7 +73,7 @@ func main() {
})

clientSet := kubernetes.NewForConfigOrDie(manager.GetConfig())
cloudProvider := registry.NewCloudProvider(cloudprovider.Options{ClientSet: clientSet})
cloudProvider := registry.NewAPI(cloudprovider.Options{ClientSet: clientSet})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO keep this as register.NewCloudProvider. I actually renamed a bunch of factories to just cloudprovider in an earlier PR to make it easier for you.

}
)

type API struct {
Copy link
Contributor

@ellistarn ellistarn Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO you should keep this concept named "cloud provider" since it's so common across the k8s ecosystem. Maybe cloudprovider.go?

@@ -26,12 +26,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type NodeFactory struct {
type NodeAPI struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sold on this naming change. This isn't an API, it's a https://en.wikipedia.org/wiki/Factory_method_pattern. Any time you see .For() in my code, it's a factory. Factories are hugely useful when necessary. In this case, the NodeFactory encapsulates some dependencies (e.g. EC2) vends node objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Good point. I'll change this back.

@@ -25,11 +25,11 @@ import (
)

// Validate cloud provider specific components of the cluster spec
func (c *Capacity) Validate(ctx context.Context) (errs *apis.FieldError) {
func (a *API) Validate(ctx context.Context, spec *v1alpha1.ProvisionerSpec) (errs *apis.FieldError) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move these functions aws/cloudprovider.go (name change recommended above). It's only a few lines, and I think the scope is easier to encapsulate now. It feels a bit awkward that this is standing alone now that the cloudprovider API surface is so much smaller (Create, Delete, Validate, GetInstanceTypes)

NotImplementedError = fmt.Errorf("provider is not implemented. Are you running the correct release for your cloud provider?")
)

type API struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't make this name change for similar reasons. This looks like a bad merge to me. I removed the NotImplementedError (which isn't used anymore) in a previous PR.

return &API{
WantErr: NotImplementedError,
NodeReplicas: make(map[string]*int32),
NodeGroupStable: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I removed this. It seems like a bad merge.

@@ -8,8 +8,8 @@ import (
"github.com/awslabs/karpenter/pkg/cloudprovider/<YOUR_PROVIDER_NAME>"
)

func NewFactory() cloudprovider.Factory {
return <YOUR_PROVIDER_NAME>.NewFactory()
func NewAPI() cloudprovider.API {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewCloudProvider imo.

// Create a set of nodes for each of the given constraints.
Create(context.Context, []*Packing) ([]*PackedNode, error)
Create(context.Context, []*Packing, *v1alpha1.Provisioner) ([]*PackedNode, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the provisioner first, imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before Packing, but not before context, right?

@@ -44,7 +44,7 @@ func TestAPIs(t *testing.T) {

var controller *Controller
var env = test.NewEnvironment(func(e *test.Environment) {
cloudProvider := &fake.Factory{}
cloudProvider := fake.NewAPI()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this change is caused by the bad merge.

Copy link
Contributor

@ellistarn ellistarn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great. A couple of naming nits and what looks like some stale code from a bad merge. But otherwise a huge simplification. I think you can go more red than this already is :D

Copy link
Contributor

@ellistarn ellistarn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-150 lines! Nice!

@ellistarn ellistarn merged commit 10f5634 into aws:main Jun 17, 2021
@njtran njtran deleted the removeFactory branch June 22, 2021 22:01
gfcroft pushed a commit to gfcroft/karpenter-provider-aws that referenced this pull request Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants