2020package org .dinky .gateway .kubernetes .utils ;
2121
2222import org .dinky .gateway .kubernetes .decorate .DinkySqlConfigMapDecorate ;
23+ import org .dinky .gateway .kubernetes .watcher .DeploymentStatusWatcher ;
2324import org .dinky .utils .TextUtil ;
2425
2526import org .apache .flink .configuration .Configuration ;
4950import io .fabric8 .kubernetes .client .Config ;
5051import io .fabric8 .kubernetes .client .DefaultKubernetesClient ;
5152import io .fabric8 .kubernetes .client .KubernetesClient ;
53+ import io .fabric8 .kubernetes .client .dsl .RollableScalableResource ;
5254import io .fabric8 .kubernetes .client .utils .Serialization ;
5355import lombok .Data ;
5456import lombok .extern .slf4j .Slf4j ;
@@ -65,9 +67,11 @@ public class K8sClientHelper {
6567 private KubernetesClient kubernetesClient ;
6668 protected Configuration configuration ;
6769 private DinkySqlConfigMapDecorate sqlFileDecorate ;
70+ private DeploymentStatusWatcher deploymentStatusWatch ;
6871
6972 public K8sClientHelper (Configuration configuration , String kubeConfig ) {
7073 this .configuration = configuration ;
74+ deploymentStatusWatch = new DeploymentStatusWatcher ();
7175 initKubeClient (kubeConfig );
7276 }
7377
@@ -113,12 +117,12 @@ private void initKubeClient(String kubeConfig) {
113117 */
114118 public Deployment createDinkyResource () {
115119 log .info ("createDinkyResource" );
116- Deployment deployment = kubernetesClient
120+ RollableScalableResource < Deployment > deploymentRollableScalableResource = kubernetesClient
117121 .apps ()
118122 .deployments ()
119123 .inNamespace (configuration .get (KubernetesConfigOptions .NAMESPACE ))
120- .withName (configuration .get (KubernetesConfigOptions .CLUSTER_ID ))
121- .get ();
124+ .withName (configuration .get (KubernetesConfigOptions .CLUSTER_ID ));
125+ Deployment deployment = deploymentRollableScalableResource .get ();
122126 List <HasMetadata > resources = getSqlFileDecorate ().buildResources ();
123127 // set owner reference
124128 OwnerReference deploymentOwnerReference = new OwnerReferenceBuilder ()
@@ -134,13 +138,15 @@ public Deployment createDinkyResource() {
134138 resource .getMetadata ().setOwnerReferences (Collections .singletonList (deploymentOwnerReference )));
135139 // create resources
136140 resources .forEach (resource -> log .info (Serialization .asYaml (resource )));
141+ deploymentRollableScalableResource .watch (deploymentStatusWatch );
137142 kubernetesClient .resourceList (resources ).createOrReplace ();
138143 return deployment ;
139144 }
140145
141146 /**
142147 * initPodTemplate
143148 * Preprocess the pod template
149+ *
144150 * @param sqlStatement
145151 * @return
146152 */
@@ -166,8 +172,7 @@ public Pod decoratePodTemplate(String sqlStatement, String podTemplate) {
166172
167173 /**
168174 * dumpPod2Str
169- *
170- * */
175+ */
171176 public String dumpPod2Str (Pod pod ) {
172177 // use snakyaml to serialize the pod
173178 Representer representer = new IgnoreNullRepresenter ();
@@ -179,9 +184,11 @@ public String dumpPod2Str(Pod pod) {
179184 Yaml yaml = new Yaml (representer , options );
180185 return yaml .dump (pod );
181186 }
187+
182188 /**
183189 * close
184190 * delete the temporary directory and close the client
191+ *
185192 * @return
186193 */
187194 public boolean close () {
0 commit comments