-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
how to load yaml file #170
Comments
may be using snakeyaml to load yaml file and convert to object Yaml yaml = new Yaml();
ExtensionsV1beta1Deployment body = yaml.loadAs(new FileReader("deployment.yaml"), ExtensionsV1beta1Deployment.class);
ExtensionsV1beta1Api api = new ExtensionsV1beta1Api();
api.createNamespacedDeployment("default", body, ""); |
This is how I do it,
|
@pycaster thanks for your answer, but it is only for create configuration. What I want to do is using yaml file to deploy resources, for example deployment or pod. I have tried @kondapally1989's way, it works. But the only problem is I have to know what kind of resource I want to create. For example, I have give the ExtensionsV1beta1Deployment.class explicitly when loading deployment.yaml. It is not that convenient. |
@zysimplelife i have written a rough and messy example class import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.models.ExtensionsV1beta1Deployment;
import io.kubernetes.client.models.V1Namespace;
import io.kubernetes.client.models.V1Service;
public class Solution {
private static final String yaml_file = "/home/karthik/Desktop/cloud/java/kubernetes/1.yaml";
static Map<String,Object> objMap = new HashMap<>();
static Yaml yaml = new Yaml();
static {
objMap.put("Deployment", ExtensionsV1beta1Deployment.class);
objMap.put("Namespace",V1Namespace.class);
objMap.put("Service", V1Service.class);
//fill the hashmap
}
public static void main(String[] args) throws FileNotFoundException, ApiException {
FileReader fr =new FileReader(yaml_file);
InputStream input = new FileInputStream(new File(yaml_file));
Map map = (Map) yaml.load(input);
ExtensionsV1beta1Deployment body = (ExtensionsV1beta1Deployment) convertyamlToObject(fr, (String) map.get("kind"));
ExtensionsV1beta1Api api = new ExtensionsV1beta1Api();
System.out.println(body);
}
public static Object convertyamlToObject(FileReader fr, String kind) {
return yaml.loadAs(fr, (Class<Object>) objMap.get(kind));
}
} |
@kondapally1989 Thanks |
Fix for this is here: |
I want to use this client to load yaml file for deployment or pod? does it support in this library?
Thanks
The text was updated successfully, but these errors were encountered: