This repository was archived by the owner on Jan 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/de/svs/doido/mongo/kubernetes/configmap/Write.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package svs.doido.mongo.kubernetes.configmap; | ||
|
||
import svs.doido.mongo.dto.Configmap; | ||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.fabric8.kubernetes.api.model.ConfigMapBuilder; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import jakarta.inject.Inject; | ||
import jakarta.enterprise.context.RequestScoped; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
@RequestScoped | ||
public class Write { | ||
|
||
@Inject | ||
KubernetesClient client; | ||
|
||
public void writeConfigmap(String namespace, String name, Configmap cfg) { | ||
ConfigMap configmap = client.configMaps().inNamespace(namespace).withName(cfg.getName()).get(); | ||
Map<String,String> labels; | ||
Map<String,String> data; | ||
ObjectMeta meta; | ||
|
||
if(configmap != NULL) { | ||
labels = configmap.getMetadata().getLabels(); | ||
if( | ||
labels.containsKey("app.kubernetes.io/name") && | ||
labels.get("app.kubernetes.io/name").equal("doido-mongo") | ||
) { | ||
data = configmap.getData(); | ||
data.put("uri", cfg.getUri); | ||
configmap.setData(data); | ||
client.configMaps().resource(configmap).createOrReplace(); | ||
} | ||
} | ||
else { | ||
labels = new HashMap<String,String>(); | ||
data = new HashMap<String,String>(); | ||
labels.put("app.kubernetes.io/name", "doido-mongo"); | ||
data.put("uri", cfg.getUri()); | ||
configmap = new ConfigMapBuilder().withNewMetadata().withName(cfg.getName()).withNamespace(namespace).and().build(); | ||
configmap.setData(data); | ||
meta = configmap.getMetadata(); | ||
meta.setLables(labels); | ||
configmap.setMetadata(meta); | ||
client.configMaps().resource(configmap).create(); | ||
} | ||
} | ||
} |