use of com.netflix.titus.ext.kube.clustermembership.connector.transport.KubeUtils in project titus-control-plane by Netflix.
the class KubeRegistrationActions method registerLocal.
public static Mono<Function<KubeClusterState, KubeClusterState>> registerLocal(KubeContext context, KubeClusterState kubeClusterState, Function<ClusterMember, ClusterMembershipRevision<ClusterMember>> selfUpdate) {
ClusterMember localMember = kubeClusterState.getLocalMemberRevision().getCurrent();
ClusterMembershipRevision<ClusterMember> newRevision = setRegistrationStatus(selfUpdate.apply(localMember), true);
KubeMembershipExecutor membershipExecutor = context.getKubeMembershipExecutor();
Mono<ClusterMembershipRevision<ClusterMember>> monoAction;
if (kubeClusterState.isRegistered()) {
monoAction = membershipExecutor.updateLocal(newRevision).onErrorResume(e -> {
if (!KubeUtils.is4xx(e)) {
return Mono.error(e);
}
int status = KubeUtils.getHttpStatusCode(e);
if (status == 404) {
return membershipExecutor.createLocal(newRevision);
}
// Bad or stale data record. Remove it first and than register.
return membershipExecutor.removeMember(newRevision.getCurrent().getMemberId()).then(membershipExecutor.createLocal(newRevision));
});
} else {
monoAction = membershipExecutor.createLocal(newRevision).onErrorResume(e -> {
if (!KubeUtils.is4xx(e)) {
return Mono.error(e);
}
// Bad or stale data record. Remove it first and than register.
return membershipExecutor.removeMember(newRevision.getCurrent().getMemberId()).then(membershipExecutor.createLocal(newRevision));
});
}
return monoAction.onErrorMap(KubeUtils::toConnectorException).map(update -> currentState -> currentState.setMustRegister(true).setLocalClusterMemberRevision(update, true));
}
Aggregations