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

[POC] Kruize VPA Integration PoC #1385

Open
wants to merge 6 commits into
base: mvp_demo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,63 @@ kind: Namespace
metadata:
name: openshift-tuning
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kruize-vpa-role
rules:
- apiGroups:
- ""
resources:
- pods
- customresourcedefinitions
verbs:
- '*'
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- '*'
- apiGroups:
- autoscaling.k8s.io
resources:
- verticalpodautoscalers
- verticalpodautoscalercheckpoints
verbs:
- '*'
- apiGroups:
- rbac.authorization.k8s.io
resources:
- clusterrolebindings
verbs:
- '*'
- apiGroups:
- apps
resources:
- deployments
verbs:
- "*"
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kruize-sa
namespace: openshift-tuning
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kruize-vpa-role-binding
subjects:
- kind: ServiceAccount
name: kruize-sa
namespace: openshift-tuning
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kruize-vpa-role
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
Expand Down
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>10.0.24</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>6.13.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/autotune/Autotune.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.autotune.analyzer.exceptions.MonitoringAgentNotFoundException;
import com.autotune.analyzer.exceptions.MonitoringAgentNotSupportedException;
import com.autotune.analyzer.performanceProfiles.MetricProfileCollection;
import com.autotune.analyzer.recommendations.updater.vpa.VpaUpdaterImpl;
import com.autotune.analyzer.utils.AnalyzerConstants;
import com.autotune.common.datasource.DataSourceCollection;
import com.autotune.common.datasource.DataSourceInfo;
Expand Down Expand Up @@ -132,6 +133,8 @@ public static void main(String[] args) {
checkAvailableDataSources();
// load available metric profiles from db
loadMetricProfilesFromDB();
// start updaters
startRecommendationUpdaters();

}
// close the existing session factory before recreating
Expand Down Expand Up @@ -287,4 +290,8 @@ private static void executeDDLs(String ddlFileName) throws Exception {
LOGGER.info(DBConstants.DB_MESSAGES.DB_LIVELINESS_PROBE_SUCCESS);
}

private static void startRecommendationUpdaters() {
VpaUpdaterImpl.getInstance().initiateUpdater();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.autotune.analyzer.exceptions;

public class InvalidRecommendationUpdaterType extends Throwable
{
public InvalidRecommendationUpdaterType() {
}

public InvalidRecommendationUpdaterType(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.autotune.analyzer.exceptions;

public class VpaObjectCreateError extends Throwable
{
public VpaObjectCreateError() {
}

public VpaObjectCreateError(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public ExperimentUseCaseType(KruizeObject kruizeObject) throws Exception {
setLocal_monitoring(true);
} else if (kruizeObject.getMode().equalsIgnoreCase(AnalyzerConstants.EXPERIMENT)) {
setLocal_experiment(true);
} else if (kruizeObject.getMode().equalsIgnoreCase(AnalyzerConstants.RECREATE)) {
setLocal_monitoring(true);
} else if (kruizeObject.getMode().equalsIgnoreCase(AnalyzerConstants.AUTO)) {
setLocal_monitoring(true);
} else {
throw new Exception("Invalid Mode " + kruizeObject.getMode() + " for target cluster as Local.");
}
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,12 @@ public void eventReceived(Action action, String resource) {
}

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

}

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

KubernetesServices kubernetesServices = new KubernetesServicesImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public KruizeObject prepareRecommendations(int calCount) throws FetchMetricsErro
if (!kruizeObject.getValidation_data().isSuccess())
return kruizeObject;
setKruizeObject(kruizeObject);
LOGGER.info("Setting Kruize Object.");
mainKruizeExperimentMAP.put(kruizeObject.getExperimentName(), kruizeObject);
// continue to generate recommendation when kruizeObject is successfully created
try {
Expand Down Expand Up @@ -1771,7 +1772,6 @@ private ValidationOutputData addRecommendationsToDB(Map<String, KruizeObject> ma
private String getResults(Map<String, KruizeObject> mainKruizeExperimentMAP, KruizeObject kruizeObject,
String experimentName, Timestamp intervalStartTime, String dataSource) throws Exception, FetchMetricsError {
String errorMsg = "";

mainKruizeExperimentMAP.put(experimentName, kruizeObject);
// get data from the DB in case of remote monitoring
if (kruizeObject.getExperiment_usecase_type().isRemote_monitoring()) {
Expand Down Expand Up @@ -2153,10 +2153,17 @@ private void fetchContainerMetricsBasedOnDataSourceAndProfile(KruizeObject kruiz
}

// If promQL is determined, fetch metrics from the datasource
// promQL = promQL
// .replace(AnalyzerConstants.NAMESPACE_VARIABLE, namespace)
// .replace(AnalyzerConstants.CONTAINER_VARIABLE, containerName)
// .replace(AnalyzerConstants.MEASUREMENT_DURATION_IN_MIN_VARAIBLE, Integer.toString(measurementDurationMinutesInDouble.intValue()))
// .replace(AnalyzerConstants.WORKLOAD_VARIABLE, workload)
// .replace(AnalyzerConstants.WORKLOAD_TYPE_VARIABLE, workload_type);

promQL = promQL
.replace(AnalyzerConstants.NAMESPACE_VARIABLE, namespace)
.replace(AnalyzerConstants.CONTAINER_VARIABLE, containerName)
.replace(AnalyzerConstants.MEASUREMENT_DURATION_IN_MIN_VARAIBLE, Integer.toString(measurementDurationMinutesInDouble.intValue()))
.replace(AnalyzerConstants.MEASUREMENT_DURATION_IN_MIN_VARAIBLE, Integer.toString(1))
.replace(AnalyzerConstants.WORKLOAD_VARIABLE, workload)
.replace(AnalyzerConstants.WORKLOAD_TYPE_VARIABLE, workload_type);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.autotune.analyzer.recommendations.updater;

import com.autotune.analyzer.exceptions.InvalidRecommendationUpdaterType;

public interface RecommendationUpdater {
RecommendationUpdaterImpl getUpdater(String updaterType) throws InvalidRecommendationUpdaterType;
boolean isUpdaterInstalled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.autotune.analyzer.recommendations.updater;

import com.autotune.analyzer.exceptions.InvalidRecommendationUpdaterType;
import com.autotune.analyzer.recommendations.updater.vpa.VpaUpdaterImpl;
import com.autotune.analyzer.utils.AnalyzerConstants;
import com.autotune.analyzer.utils.AnalyzerErrorConstants;

import java.util.Objects;

public class RecommendationUpdaterImpl implements RecommendationUpdater{

@Override
public RecommendationUpdaterImpl getUpdater(String updaterType) throws InvalidRecommendationUpdaterType {
if (AnalyzerConstants.RecommendationUpdaterConstants.VPA_UPDATER.equalsIgnoreCase(updaterType)) {
return VpaUpdaterImpl.getInstance();
} else {
throw new InvalidRecommendationUpdaterType(String.format(AnalyzerErrorConstants.RecommendationUpdaterErrorConstant.INVALID_UPDATER_TYPE, updaterType));
}
}

@Override
public boolean isUpdaterInstalled() {
return false;
}
}
Loading