-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: "spark-submit jar on k8s" related label and resource expansion #4784
Changes from 5 commits
adf7ae5
05f03e7
f445f4a
ad669b1
61c77e6
53a7dcd
e4d16ed
e1df7e2
ad60b9e
f85510e
0dddd69
0ec91aa
4d8ea2f
67f440a
0c7ff06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.linkis.manager.rm.external.kubernetes; | ||
|
||
import org.apache.linkis.manager.common.entity.resource.ResourceType; | ||
import org.apache.linkis.manager.rm.external.domain.ExternalResourceIdentifier; | ||
|
||
public class KubernetesResourceIdentifier implements ExternalResourceIdentifier { | ||
@Override | ||
public ResourceType getResourceType() { | ||
return ResourceType.Kubernetes; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.linkis.manager.rm.external.kubernetes; | ||
|
||
import org.apache.linkis.manager.common.entity.resource.*; | ||
import org.apache.linkis.manager.rm.external.domain.ExternalAppInfo; | ||
import org.apache.linkis.manager.rm.external.domain.ExternalResourceIdentifier; | ||
import org.apache.linkis.manager.rm.external.domain.ExternalResourceProvider; | ||
import org.apache.linkis.manager.rm.external.request.ExternalResourceRequester; | ||
|
||
import java.util.*; | ||
|
||
import io.fabric8.kubernetes.api.model.Node; | ||
import io.fabric8.kubernetes.api.model.metrics.v1beta1.NodeMetrics; | ||
import io.fabric8.kubernetes.client.ConfigBuilder; | ||
import io.fabric8.kubernetes.client.DefaultKubernetesClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class KubernetesResourceRequester implements ExternalResourceRequester { | ||
private static final Logger logger = LoggerFactory.getLogger(KubernetesResourceRequester.class); | ||
private ExternalResourceProvider provider = null; | ||
private String k8sMasterUrl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How to support different namespaces and different queues? |
||
private String k8sClientCertData; | ||
private String k8sClientKeyData; | ||
private String k8sCaCertData; | ||
|
||
@Override | ||
public NodeResource requestResourceInfo( | ||
ExternalResourceIdentifier identifier, ExternalResourceProvider provider) { | ||
k8sMasterUrl = (String) provider.getConfigMap().get("k8sMasterUrl"); | ||
k8sClientCertData = (String) provider.getConfigMap().get("k8sClientCertData"); | ||
k8sClientKeyData = (String) provider.getConfigMap().get("k8sClientKeyData"); | ||
k8sCaCertData = (String) provider.getConfigMap().get("k8sCaCertData"); | ||
this.provider = provider; | ||
DefaultKubernetesClient client = | ||
new DefaultKubernetesClient( | ||
new ConfigBuilder() | ||
.withMasterUrl(k8sMasterUrl) | ||
.withClientCertData(k8sClientCertData) | ||
.withClientKeyData(k8sClientKeyData) | ||
.withCaCertData(k8sCaCertData) | ||
.build()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering if |
||
long usedMemory = 0; | ||
long allocatableMemory = 0; | ||
long usedCPU = 0; | ||
long allocatableCPU = 0; | ||
for (NodeMetrics item : client.top().nodes().metrics().getItems()) { | ||
usedMemory += Long.parseLong(item.getUsage().get("memory").getAmount()); | ||
usedCPU += Long.parseLong(item.getUsage().get("cpu").getAmount()) / 1000000L; | ||
} | ||
for (Node item : client.nodes().list().getItems()) { | ||
allocatableMemory += | ||
Long.parseLong(item.getStatus().getAllocatable().get("memory").getAmount()); | ||
allocatableCPU += Long.parseLong(item.getStatus().getAllocatable().get("cpu").getAmount()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whether the reference |
||
} | ||
logger.info( | ||
"usedMemory: {}, usedCPU: {}, allocatableMemory: {}, allocatableCPU: {}", | ||
usedMemory, | ||
usedCPU, | ||
allocatableMemory, | ||
allocatableCPU); | ||
CommonNodeResource nodeResource = new CommonNodeResource(); | ||
nodeResource.setMaxResource( | ||
new KubernetesResource(allocatableMemory * 1024L, allocatableCPU * 1000L)); | ||
nodeResource.setUsedResource(new KubernetesResource(usedMemory * 1024L, usedCPU)); | ||
client.close(); | ||
return nodeResource; | ||
} | ||
|
||
@Override | ||
public List<ExternalAppInfo> requestAppInfo( | ||
ExternalResourceIdentifier identifier, ExternalResourceProvider provider) { | ||
// TODO | ||
return null; | ||
} | ||
|
||
@Override | ||
public ResourceType getResourceType() { | ||
return ResourceType.Kubernetes; | ||
} | ||
|
||
@Override | ||
public Boolean reloadExternalResourceAddress(ExternalResourceProvider provider) { | ||
if (null == provider) { | ||
k8sMasterUrl = null; | ||
k8sClientCertData = null; | ||
k8sClientKeyData = null; | ||
k8sCaCertData = null; | ||
} else { | ||
k8sMasterUrl = (String) provider.getConfigMap().get("k8sMasterUrl"); | ||
k8sClientCertData = (String) provider.getConfigMap().get("k8sClientCertData"); | ||
k8sClientKeyData = (String) provider.getConfigMap().get("k8sClientKeyData"); | ||
k8sCaCertData = (String) provider.getConfigMap().get("k8sCaCertData"); | ||
} | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.linkis.manager.rm.external.parser; | ||
|
||
import org.apache.linkis.manager.common.entity.resource.ResourceType; | ||
import org.apache.linkis.manager.rm.external.domain.ExternalResourceIdentifier; | ||
import org.apache.linkis.manager.rm.external.kubernetes.KubernetesResourceIdentifier; | ||
|
||
import java.util.Map; | ||
|
||
public class KubernetesResourceIdentifierParser implements ExternalResourceIdentifierParser { | ||
|
||
@Override | ||
public ExternalResourceIdentifier parse(Map<String, Object> identifierMap) { | ||
return new KubernetesResourceIdentifier(); | ||
} | ||
|
||
@Override | ||
public ResourceType getResourceType() { | ||
return ResourceType.Kubernetes; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.linkis.manager.rm.service.impl; | ||
|
||
import org.apache.linkis.manager.common.entity.resource.*; | ||
import org.apache.linkis.manager.common.exception.RMWarnException; | ||
import org.apache.linkis.manager.rm.domain.RMLabelContainer; | ||
import org.apache.linkis.manager.rm.external.kubernetes.KubernetesResourceIdentifier; | ||
import org.apache.linkis.manager.rm.external.service.ExternalResourceService; | ||
import org.apache.linkis.manager.rm.service.LabelResourceService; | ||
import org.apache.linkis.manager.rm.service.RequestResourceService; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.apache.linkis.manager.common.entity.resource.ResourceType.DriverAndKubernetes; | ||
|
||
public class DriverAndKubernetesReqResourceService extends RequestResourceService { | ||
private static final Logger logger = | ||
LoggerFactory.getLogger(DriverAndKubernetesReqResourceService.class); | ||
private LabelResourceService labelResourceService; | ||
private ExternalResourceService externalResourceService; | ||
private final ResourceType resourceType = DriverAndKubernetes; | ||
|
||
public DriverAndKubernetesReqResourceService( | ||
LabelResourceService labelResourceService, ExternalResourceService externalResourceService) { | ||
super(labelResourceService); | ||
this.labelResourceService = labelResourceService; | ||
this.externalResourceService = externalResourceService; | ||
} | ||
|
||
@Override | ||
public ResourceType resourceType() { | ||
return this.resourceType; | ||
} | ||
|
||
@Override | ||
public boolean canRequest(RMLabelContainer labelContainer, NodeResource resource) | ||
throws RMWarnException { | ||
// if (!super.canRequest(labelContainer, resource)) { | ||
// return false; | ||
// } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the configuration resource not validated? |
||
DriverAndKubernetesResource requestedDriverAndKubernetesResource = | ||
(DriverAndKubernetesResource) resource.getMaxResource(); | ||
KubernetesResource requestedKubernetesResource = | ||
requestedDriverAndKubernetesResource.getKubernetesResource(); | ||
|
||
KubernetesResourceIdentifier kubernetesResourceIdentifier = new KubernetesResourceIdentifier(); | ||
NodeResource providedKubernetesResource = | ||
externalResourceService.getResource( | ||
ResourceType.Kubernetes, labelContainer, kubernetesResourceIdentifier); | ||
Resource maxCapacity = providedKubernetesResource.getMaxResource(); | ||
Resource usedCapacity = providedKubernetesResource.getUsedResource(); | ||
|
||
logger.info( | ||
"Kubernetes resource: used resource:" + usedCapacity + " and max resource: " + maxCapacity); | ||
Resource leftResource = maxCapacity.minus(usedCapacity); | ||
logger.info( | ||
"Kubernetes resource: left " | ||
+ leftResource | ||
+ ", this request requires: " | ||
+ requestedKubernetesResource); | ||
if (leftResource.less(requestedKubernetesResource)) { | ||
logger.info( | ||
"user: " | ||
+ labelContainer.getUserCreatorLabel().getUser() | ||
+ " request kubernetes resource " | ||
+ requestedKubernetesResource | ||
+ " > left resource " | ||
+ leftResource); | ||
// Pair<Integer, String> notEnoughMessage = | ||
// generateQueueNotEnoughMessage(requestedYarnResource, queueLeftResource, | ||
// maxCapacity); | ||
// throw new RMWarnException(notEnoughMessage.getKey(), notEnoughMessage.getValue()); | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use props value?