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

Implement auto detection #221

Merged
merged 4 commits into from Jul 29, 2020
Merged

Implement auto detection #221

merged 4 commits into from Jul 29, 2020

Conversation

leszko
Copy link

@leszko leszko commented Jul 23, 2020

Note that:

  • We will need to release with the com.hazelcast:hazelcast:4.1-SNAPSHOT dependency
  • This change is 100% backward-compatible (new released hazelcast-kubernetes can be used with older hazelcast versions)
  • Apart from auto-detection, the logs are improved

After this change, IMO the newbie experience is great.

  1. Start Hazelcast on Kubernetes
$ kubectl run hazelcast --image=leszko/hazelcast
$ kubectl logs hazelcast
...
WARNING: Kubernetes API access is forbidden! Starting standalone. To use Hazelcast Kubernetes discovery configure the required RBAC. For 'default' service account in 'default' namespace execute: `kubectl apply -f https://raw.githubusercontent.com/hazelcast/hazelcast-kubernetes/master/rbac.yaml`
Jul 23, 2020 2:05:32 PM com.hazelcast.internal.cluster.ClusterService
INFO: [10.8.1.4]:5701 [dev] [4.1-SNAPSHOT]

Members {size:1, ver:1} [
        Member [10.8.1.4]:5701 - 44a54bd1-34ca-4f8c-93fe-d1ce594eacac this
]

Jul 23, 2020 2:05:32 PM com.hazelcast.core.LifecycleService
INFO: [10.8.1.4]:5701 [dev] [4.1-SNAPSHOT] [10.8.1.4]:5701 is STARTED
  1. Execute the recommended command.
$ kubectl apply -f https://raw.githubusercontent.com/hazelcast/hazelcast-kubernetes/master/rbac.yaml
  1. Restart Hazelcast and create two instances
$ kubectl delete pod/hazelcast
$ kubectl run hazelcast --image=leszko/hazelcast
$ kubectl run hazelcast-2 --image=leszko/hazelcast
$ kubectl logs hazelcast
...
Members {size:2, ver:2} [
        Member [10.8.1.5]:5701 - 6df84047-4510-460a-ba27-ff75378d217a
        Member [10.8.2.4]:5701 - eb55802e-8358-4931-af88-bac1eaf3819f this
]

No configuration needed!

@Override
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
public boolean isAutoDetectionApplicable() {
return new File("/var/run/secrets/kubernetes.io/serviceaccount/token").exists();
Copy link
Contributor

@pivovarit pivovarit Jul 23, 2020

Choose a reason for hiding this comment

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

Use Files.isRegularFile(path) instead. Otherwise, you'd need to check if the file is not a directory as well.

Apparently, it's faster as well 🤷‍♀️

Copy link
Author

Choose a reason for hiding this comment

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

Isn't it actually slower? https://rules.sonarsource.com/java/tag/performance/RSPEC-3725

FYI: This will never be a directory, so not a big deal with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

As I see there used to be a bug on JDK 8 which got fixed later on. However, I don't see any signs that it was backported JDK 8, so I guess we can leave it as is 🤷‍♂️

@leszko leszko marked this pull request as draft July 24, 2020 08:38
@leszko leszko changed the title [Do not merge yet] Implement auto detection Implement auto detection Jul 24, 2020
@leszko leszko marked this pull request as ready for review July 29, 2020 13:42
@pivovarit pivovarit self-requested a review July 29, 2020 13:46
@leszko
Copy link
Author

leszko commented Jul 29, 2020

verify

@leszko leszko merged commit 1f1b858 into hazelcast:master Jul 29, 2020
@leszko leszko deleted the auto-detection branch July 29, 2020 14:37
@leszko leszko added this to the 2.1 milestone Aug 21, 2020
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.

None yet

2 participants