34
34
import static cd .go .contrib .elasticagent .KubernetesPlugin .LOG ;
35
35
import static cd .go .contrib .elasticagent .executors .GetProfileMetadataExecutor .SPECIFIED_USING_POD_CONFIGURATION ;
36
36
import static cd .go .contrib .elasticagent .utils .Util .getSimpleDateFormat ;
37
+ import static java .text .MessageFormat .format ;
37
38
38
39
public class KubernetesAgentInstances implements AgentInstances <KubernetesInstance > {
39
40
private final ConcurrentHashMap <String , KubernetesInstance > instances = new ConcurrentHashMap <>();
@@ -58,14 +59,14 @@ public KubernetesAgentInstances(KubernetesClientFactory factory, KubernetesInsta
58
59
59
60
@ Override
60
61
public KubernetesInstance create (CreateAgentRequest request , PluginSettings settings , PluginRequest pluginRequest ) throws Exception {
61
- final Integer maxAllowedContainers = settings .getMaximumPendingAgentsCount ();
62
+ final Integer maxAllowedContainers = settings .getMaxPendingPods ();
62
63
synchronized (instances ) {
63
64
doWithLockOnSemaphore (new SetupSemaphore (maxAllowedContainers , instances , semaphore ));
64
65
65
66
if (semaphore .tryAcquire ()) {
66
67
return createKubernetesInstance (request , settings , pluginRequest );
67
68
} else {
68
- LOG .warn (String . format ("The number of pending kubernetes pods is currently at the maximum permissible limit (%d ). Total kubernetes pods (%d ). Not creating any more containers." , maxAllowedContainers , instances .size ()));
69
+ LOG .warn (format ("The number of pending kubernetes pods is currently at the maximum permissible limit ({0} ). Total kubernetes pods ({1} ). Not creating any more containers." , maxAllowedContainers , instances .size ()));
69
70
return null ;
70
71
}
71
72
}
@@ -77,14 +78,14 @@ private void doWithLockOnSemaphore(Runnable runnable) {
77
78
}
78
79
}
79
80
80
- private KubernetesInstance createKubernetesInstance (CreateAgentRequest request , PluginSettings settings , PluginRequest pluginRequest ) throws Exception {
81
+ private KubernetesInstance createKubernetesInstance (CreateAgentRequest request , PluginSettings settings , PluginRequest pluginRequest ) {
81
82
JobIdentifier jobIdentifier = request .jobIdentifier ();
82
83
if (isAgentCreatedForJob (jobIdentifier .getJobId ())) {
83
- LOG .warn ("[Create Agent Request] Request for creating an agent for Job Identifier [" + jobIdentifier + " ] has already been scheduled. Skipping current request." );
84
+ LOG .warn (format ( "[Create Agent Request] Request for creating an agent for Job Identifier [{0} ] has already been scheduled. Skipping current request." , jobIdentifier ) );
84
85
return null ;
85
86
}
86
87
87
- KubernetesClient client = factory .kubernetes (settings );
88
+ KubernetesClient client = factory .client (settings );
88
89
KubernetesInstance instance = kubernetesInstanceFactory .create (request , settings , client , pluginRequest , isUsingPodYaml (request ));
89
90
register (instance );
90
91
@@ -109,10 +110,10 @@ private boolean isUsingPodYaml(CreateAgentRequest request) {
109
110
public void terminate (String agentId , PluginSettings settings ) throws Exception {
110
111
KubernetesInstance instance = instances .get (agentId );
111
112
if (instance != null ) {
112
- KubernetesClient client = factory .kubernetes (settings );
113
+ KubernetesClient client = factory .client (settings );
113
114
instance .terminate (client );
114
115
} else {
115
- LOG .warn ("Requested to terminate an instance that does not exist " + agentId );
116
+ LOG .warn (format ( "Requested to terminate an instance that does not exist {0}." , agentId ) );
116
117
}
117
118
instances .remove (agentId );
118
119
}
@@ -124,7 +125,7 @@ public void terminateUnregisteredInstances(PluginSettings settings, Agents agent
124
125
return ;
125
126
}
126
127
127
- LOG .warn ("Terminating instances that did not register " + toTerminate .instances .keySet ());
128
+ LOG .warn (format ( "Terminating instances that did not register {0}." , toTerminate .instances .keySet () ));
128
129
for (KubernetesInstance container : toTerminate .instances .values ()) {
129
130
terminate (container .name (), settings );
130
131
}
@@ -147,9 +148,9 @@ public Agents instancesCreatedAfterTimeout(PluginSettings settings, Agents agent
147
148
}
148
149
149
150
@ Override
150
- public void refreshAll (PluginRequest pluginRequest ) throws Exception {
151
- LOG .debug ("[Refresh Instances]. Syncing k8s elastic agent pod information" );
152
- KubernetesClient client = factory .kubernetes (pluginRequest .getPluginSettings ());
151
+ public void refreshAll (PluginRequest pluginRequest ) {
152
+ LOG .debug ("[Refresh Instances]. Syncing k8s elastic agent pod information. " );
153
+ KubernetesClient client = factory .client (pluginRequest .getPluginSettings ());
153
154
PodList list = client .pods ().inNamespace (Constants .KUBERNETES_NAMESPACE ).list ();
154
155
155
156
for (Pod pod : list .getItems ()) {
@@ -174,7 +175,7 @@ private void register(KubernetesInstance instance) {
174
175
private KubernetesAgentInstances unregisteredAfterTimeout (PluginSettings settings , Agents knownAgents ) throws Exception {
175
176
Period period = settings .getAutoRegisterPeriod ();
176
177
KubernetesAgentInstances unregisteredInstances = new KubernetesAgentInstances ();
177
- KubernetesClient client = factory .kubernetes (settings );
178
+ KubernetesClient client = factory .client (settings );
178
179
179
180
for (String instanceName : instances .keySet ()) {
180
181
if (knownAgents .containsAgentWithId (instanceName )) {
0 commit comments