|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace RenokiCo\PhpK8s\Kinds; |
| 4 | + |
| 5 | +use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster; |
| 6 | +use RenokiCo\PhpK8s\Contracts\Podable; |
| 7 | +use RenokiCo\PhpK8s\Contracts\Watchable; |
| 8 | +use RenokiCo\PhpK8s\Traits\HasLabels; |
| 9 | +use RenokiCo\PhpK8s\Traits\HasMinimumSurge; |
| 10 | +use RenokiCo\PhpK8s\Traits\HasPods; |
| 11 | +use RenokiCo\PhpK8s\Traits\HasSelector; |
| 12 | +use RenokiCo\PhpK8s\Traits\HasSpec; |
| 13 | +use RenokiCo\PhpK8s\Traits\HasStatus; |
| 14 | +use RenokiCo\PhpK8s\Traits\HasStatusConditions; |
| 15 | +use RenokiCo\PhpK8s\Traits\HasTemplate; |
| 16 | + |
| 17 | +class K8sDaemonSet extends K8sResource implements InteractsWithK8sCluster, Podable, Watchable |
| 18 | +{ |
| 19 | + use HasLabels; |
| 20 | + use HasMinimumSurge; |
| 21 | + use HasPods; |
| 22 | + use HasSelector; |
| 23 | + use HasSpec; |
| 24 | + use HasStatus; |
| 25 | + use HasStatusConditions; |
| 26 | + use HasTemplate; |
| 27 | + |
| 28 | + /** |
| 29 | + * The resource Kind parameter. |
| 30 | + * |
| 31 | + * @var null|string |
| 32 | + */ |
| 33 | + protected static $kind = 'DaemonSet'; |
| 34 | + |
| 35 | + /** |
| 36 | + * The default version for the resource. |
| 37 | + * |
| 38 | + * @var string |
| 39 | + */ |
| 40 | + protected static $stableVersion = 'apps/v1'; |
| 41 | + |
| 42 | + /** |
| 43 | + * Wether the resource has a namespace. |
| 44 | + * |
| 45 | + * @var bool |
| 46 | + */ |
| 47 | + protected static $namespaceable = true; |
| 48 | + |
| 49 | + /** |
| 50 | + * Set the updating strategy for the set. |
| 51 | + * |
| 52 | + * @param string $strategy |
| 53 | + * @param int $maxUnavailable |
| 54 | + * @return $this |
| 55 | + */ |
| 56 | + public function setUpdateStrategy(string $strategy, int $maxUnavailable = 1) |
| 57 | + { |
| 58 | + if ($strategy === 'RollingUpdate') { |
| 59 | + $this->setSpec('updateStrategy.rollingUpdate.maxUnavailable', $maxUnavailable); |
| 60 | + } |
| 61 | + |
| 62 | + return $this->setSpec('updateStrategy.type', $strategy); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Get the path, prefixed by '/', that points to the resources list. |
| 67 | + * |
| 68 | + * @return string |
| 69 | + */ |
| 70 | + public function allResourcesPath(): string |
| 71 | + { |
| 72 | + return "/apis/{$this->getApiVersion()}/namespaces/{$this->getNamespace()}/daemonsets"; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Get the path, prefixed by '/', that points to the specific resource. |
| 77 | + * |
| 78 | + * @return string |
| 79 | + */ |
| 80 | + public function resourcePath(): string |
| 81 | + { |
| 82 | + return "/apis/{$this->getApiVersion()}/namespaces/{$this->getNamespace()}/daemonsets/{$this->getIdentifier()}"; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Get the path, prefixed by '/', that points to the resource watch. |
| 87 | + * |
| 88 | + * @return string |
| 89 | + */ |
| 90 | + public function allResourcesWatchPath(): string |
| 91 | + { |
| 92 | + return "/apis/{$this->getApiVersion()}/watch/daemonsets"; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Get the path, prefixed by '/', that points to the specific resource to watch. |
| 97 | + * |
| 98 | + * @return string |
| 99 | + */ |
| 100 | + public function resourceWatchPath(): string |
| 101 | + { |
| 102 | + return "/apis/{$this->getApiVersion()}/watch/namespaces/{$this->getNamespace()}/daemonsets/{$this->getIdentifier()}"; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Get the selector for the pods that are owned by this resource. |
| 107 | + * |
| 108 | + * @return array |
| 109 | + */ |
| 110 | + public function podsSelector(): array |
| 111 | + { |
| 112 | + return [ |
| 113 | + 'daemonset-name' => $this->getName(), |
| 114 | + ]; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Get the number of scheduled nodes that run the DaemonSet. |
| 119 | + * |
| 120 | + * @return int |
| 121 | + */ |
| 122 | + public function getScheduledCount(): int |
| 123 | + { |
| 124 | + return $this->getStatus('currentNumberScheduled', 0); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Get the number of scheduled nodes that should not run the DaemonSet. |
| 129 | + * |
| 130 | + * @return int |
| 131 | + */ |
| 132 | + public function getMisscheduledCount(): int |
| 133 | + { |
| 134 | + return $this->getStatus('numberMisscheduled', 0); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Get the number of total nodes that should run the DaemonSet. |
| 139 | + * |
| 140 | + * @return int |
| 141 | + */ |
| 142 | + public function getNodesCount(): int |
| 143 | + { |
| 144 | + return $this->getStatus('numberAvailable', 0); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Get the total desired nodes that run the DaemonSet. |
| 149 | + * |
| 150 | + * @return int |
| 151 | + */ |
| 152 | + public function getDesiredCount(): int |
| 153 | + { |
| 154 | + return $this->getStatus('desiredNumberScheduled', 0); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Get the total nodes that are running the DaemonSet. |
| 159 | + * |
| 160 | + * @return int |
| 161 | + */ |
| 162 | + public function getReadyCount(): int |
| 163 | + { |
| 164 | + return $this->getStatus('numberReady', 0); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Get the total nodes that are unavailable to process the DaemonSet. |
| 169 | + * |
| 170 | + * @return int |
| 171 | + */ |
| 172 | + public function getUnavailableClount(): int |
| 173 | + { |
| 174 | + return $this->getStatus('numberUnavailable', 0); |
| 175 | + } |
| 176 | +} |
0 commit comments