Skip to content

Commit

Permalink
updating fabric8 version
Browse files Browse the repository at this point in the history
Signed-off-by: Shekhar Saxena <[email protected]>
  • Loading branch information
shekhar316 committed Dec 5, 2024
1 parent 9d09ba0 commit 5c2972d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>autotune</artifactId>
<version>0.2</version>
<properties>
<fabric8-version>4.13.2</fabric8-version>
<fabric8-version>6.13.4</fabric8-version>
<org-json-version>20240303</org-json-version>
<jetty-version>12.0.12</jetty-version>
<slf4j-version>2.17.1</slf4j-version>
Expand Down Expand Up @@ -72,6 +72,12 @@
<version>${fabric8-version}</version>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>verticalpodautoscaler-client</artifactId>
<version>${fabric8-version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.gson.Gson;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void eventReceived(Action action, String resource) {
}

@Override
public void onClose(KubernetesClientException e) { }
public void onClose(WatcherException e) { }
};

KubernetesServices kubernetesServices = new KubernetesServicesImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
import io.fabric8.kubernetes.api.model.apps.DeploymentSpec;
import io.fabric8.kubernetes.api.model.apps.DeploymentStatus;
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.*;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -224,9 +220,16 @@ public List<ReplicaSet> getReplicasBy(String namespace, String labelKey, String
*/
@Override
public Map<String, Object> getCRDEnvMap(CustomResourceDefinitionContext crd, String namespace, String kubernetesType) {
GenericKubernetesResource kubernetesResource = null;
Map<String, Object> envMap = null;
try {
envMap = kubernetesClient.customResource(crd).get(namespace, kubernetesType);
kubernetesResource = kubernetesClient.genericKubernetesResources(crd)
.inNamespace(namespace)
.withName(crd.getName())
.get();
if (kubernetesResource != null) {
envMap = kubernetesResource.getAdditionalProperties();
}
} catch (Exception e) {
new TargetHandlerException(e, "getCRDEnvMap failed!");
}
Expand Down Expand Up @@ -418,9 +421,9 @@ public Deployment amendDeployment(String namespace, String deploymentName, Deplo
@Override
public void addWatcher(CustomResourceDefinitionContext crd, Watcher watcher) {
try {
RawCustomResourceOperationsImpl rawCustomResourceOperations = kubernetesClient.customResource(crd);
if (null != rawCustomResourceOperations.list())
rawCustomResourceOperations.watch(watcher);
kubernetesClient.genericKubernetesResources(crd)
.inAnyNamespace()
.watch(watcher);
} catch (Exception e) {
LOGGER.warn("Watcher not added! Only REST API access is enabled.");
}
Expand All @@ -437,7 +440,7 @@ public void addWatcher(CustomResourceDefinitionContext crd, Watcher watcher) {
public Event getEvent(String namespace, String eventName) {
Event event = null;
try {
event = kubernetesClient.events().inNamespace(namespace).withName(eventName).get();
event = kubernetesClient.v1().events().inNamespace(namespace).withName(eventName).get();
} catch (Exception e) {
new TargetHandlerException(e, "getEvent failed! Event : " + event + " not found!");
}
Expand All @@ -456,7 +459,7 @@ public Event getEvent(String namespace, String eventName) {
public boolean replaceEvent(String namespace, String eventName, Event newEvent) {
boolean replaced = false;
try {
kubernetesClient.events().inNamespace(namespace).withName(eventName).replace(newEvent);
kubernetesClient.v1().events().inNamespace(namespace).withName(eventName).replace(newEvent);
replaced = true;
} catch (Exception e) {
new TargetHandlerException(e, "replaceEvent for the eventName " + eventName + " failed!");
Expand All @@ -476,7 +479,7 @@ public boolean replaceEvent(String namespace, String eventName, Event newEvent)
public boolean createEvent(String namespace, String eventName, Event newEvent) {
boolean created = false;
try {
kubernetesClient.events().inNamespace(namespace).withName(eventName).create(newEvent);
kubernetesClient.v1().events().inNamespace(namespace).withName(eventName).create(newEvent);
created = true;
} catch (Exception e) {
new TargetHandlerException(e, "createEvent for the eventName " + eventName + " failed!");
Expand All @@ -491,19 +494,19 @@ public boolean createEvent(String namespace, String eventName, Event newEvent) {
*/
@Override
public void watchEndpoints(CustomResourceDefinitionContext crd) {
Watcher<String> autotuneObjectWatcher = new Watcher<>() {
Watcher<GenericKubernetesResource> autotuneObjectWatcher = new Watcher<>() {

@Override
public void eventReceived(Action action, String resource) {
public void eventReceived(Action action, GenericKubernetesResource genericKubernetesResource) {
}

@Override
public void onClose(KubernetesClientException cause) {
public void onClose(WatcherException e) {
}
};
try {
kubernetesClient.customResource(crd).watch(autotuneObjectWatcher);
} catch (IOException e) {
kubernetesClient.genericKubernetesResources(crd).watch(autotuneObjectWatcher);
} catch (Exception e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.autotune.experimentManager.transitions.util.TransistionHelper;
import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentSpec;
import io.fabric8.kubernetes.api.model.apps.DeploymentStrategy;
import io.fabric8.kubernetes.api.model.apps.RollingUpdateDeployment;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand Down Expand Up @@ -32,7 +34,17 @@ public void transit(String runId) {
IntOrString maxUnavailable = new IntOrString(0);
rud.setMaxSurge(maxSurge);
rud.setMaxUnavailable(maxUnavailable);
client.apps().deployments().inNamespace(trialData.getConfig().getDeploymentNamespace()).withName(trialData.getConfig().getDeploymentName()).edit().editSpec().editOrNewStrategy().withRollingUpdate(rud).endStrategy().endSpec().done();
client.apps().deployments().inNamespace(trialData.getConfig().getDeploymentNamespace()).withName(trialData.getConfig().getDeploymentName()).edit(deployment -> {
DeploymentSpec spec = deployment.getSpec();
if (spec != null) {
if (spec.getStrategy() == null) {
spec.setStrategy(new DeploymentStrategy());
}
spec.getStrategy().setRollingUpdate(rud);
spec.getStrategy().setType("RollingUpdate");
}
return deployment;
});
Deployment defaultDeployment = client.apps().deployments().inNamespace(trialData.getConfig().getDeploymentNamespace()).withName(trialData.getConfig().getDeploymentName()).get();
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/autotune/operator/KruizeOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void eventReceived(Action action, String resource) {


@Override
public void onClose(KubernetesClientException e) {
public void onClose(WatcherException e) {
}
};

Expand Down Expand Up @@ -154,7 +155,7 @@ public void eventReceived(Action action, String resource) {
}

@Override
public void onClose(KubernetesClientException e) {
public void onClose(WatcherException e) {
}
};

Expand Down

0 comments on commit 5c2972d

Please sign in to comment.