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

Rip out activesupport #2

Closed
wants to merge 1 commit into from
Closed

Rip out activesupport #2

wants to merge 1 commit into from

Conversation

KnVerey
Copy link
Contributor

@KnVerey KnVerey commented Jan 18, 2017

@kirs @sirupsen @Shopify/byroot
This rips out the dependency on ActiveSupport to get around https://github.com/Shopify/shipit/issues/124. As you can see, not having it is a very small inconvenience.

I did a quick 🎩 of a happy path deploy of my test app.

@@ -293,23 +288,48 @@ class KubernetesDeploy
end
end

module DescendantsTracker
Copy link
Contributor Author

Choose a reason for hiding this comment

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

end

def for_type(type, name, namespace, file)
if subclass = direct_descendants.find { |subclass| subclass.handled_type.downcase == type }
Copy link
Contributor

Choose a reason for hiding this comment

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

If what you need is getting Service.new from "service" as a string, you can do the following:

type = "service"
Object.const_get(type.capitalize)

This way you won't need DescendantsTracker at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True (even KubernetesResource.const_get(type.capitalize), I believe?), but is that really better? It feels like a bit of a cheat (i.e. reliable because by convention constants capitalized "Randomtype" will be classes), and it would prevent us from camelizing the class names (e.g. PersistentVolumeClaim -> Persistentvolumeclaim).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is how Ruby developers usually do (iterating over DescendantsTracker sounds like an antipattern in this case).

For PVL, the right thing would be:

irb(main):025:0> "persistent_volume_claim".classify
=> "PersistentVolumeClaim"

(classify comes from AS)

Copy link
Contributor

Choose a reason for hiding this comment

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

(assuming persistent_volume_claim comes from the type)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(assuming persistent_volume_claim comes from the type)

Sadly no. This is coming from kubectl as persistentvolumeclaim.

This is how Ruby developers usually do (iterating over DescendantsTracker sounds like an antipattern in this case). For PVL, the right thing would be: ... (classify comes from AS)

Calling it an antipattern doesn't really help me understand why you think one option is better than the other. Both approaches are available in ActiveSupport. What I want is to find the subclass that exists to support that type, so doing exactly that doesn't sound inherently bad to me.

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 say antipattern. But it's definitely better to strive for "strategy pattern" over iterating on all candidates to find what you are looking for.

Not that it makes a huge difference performance wise (since in this kind of cases, the candidates set is generally small), but it usually makes simpler, more direct code to read.

NB: I'm just answering this specific thread cause I saw some keywords that triggered me. But I haven't kept a close watch on that PR, so feel free to disregard my opinion.

@KnVerey
Copy link
Contributor Author

KnVerey commented Jan 20, 2017

Closing. The dependency problem was fixed quickly enough that this wasn't necessary.

@KnVerey KnVerey closed this Jan 20, 2017
@KnVerey KnVerey deleted the no-activesupport branch January 20, 2017 15:37
dturn added a commit that referenced this pull request Jan 11, 2018
# This is the 1st commit message:

New tests

# This is the commit message #2:

Rework restart test
breunigs added a commit to breunigs/krane that referenced this pull request Mar 31, 2020
Disable deprecated annotation warning
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.

3 participants