PHP K8s
Github Repo
master
master
  • ๐ŸšขIntroduction
  • ๐ŸŽ‰Support
  • โซUpgrading to 3.x
  • Getting Started
    • ๐Ÿš€Installation
    • ๐Ÿ™ŒShowcase
    • ๐Ÿ”’Authentication
    • โ™ป๏ธActive Development
      • ๐Ÿ“—Default Versions
      • ๐Ÿง™Supported Kubernetes versions
      • ๐Ÿ—ณ๏ธPackage versioning
  • Cluster Interaction
    • ๐ŸงญGetting Started
    • ๐ŸŽญCRUD Operations
    • ๐Ÿ“ฆImport from YAML
    • ๐Ÿ‘€Watching Resources
  • Resources
    • ๐Ÿ‘“Base Resource
      • Attributes Methods
      • Metadata Methods
      • Custom Callers
    • ๐Ÿง‘Namespace
    • ๐Ÿ–ฅ๏ธNode
    • ๐Ÿ“กEvent
    • ๐Ÿ“ฆWorkloads
      • Pod
      • Deployment
      • StatefulSet
      • DaemonSet
      • Job
      • CronJob
    • ๐ŸงตConfigurations
      • ConfigMap
      • Secret
    • ๐Ÿ“€Storage
      • StorageClass
      • PersistentVolume
      • PersistentVolumeClaim
    • ๐Ÿ“ถNetworking
      • Service
      • Ingress
    • โ†”๏ธScaling & Availability
      • HorizontalPodAutoscaler
      • PodDisruptionBudget
    • ๐Ÿ”‘RBAC
      • ClusterRole
      • ClusterRoleBinding
      • Role
      • RoleBinding
      • ServiceAccount
  • Instances
    • Affinity
    • Container
    • Container Probes
    • Expressions
    • Resource Metrics
    • RBAC Rules
    • Volumes
  • Advanced
    • ๐ŸฐMacros
    • โœจCreate classes for CRDs
      • ๐ŸŽ‡Getting started
      • ๐ŸฐMacros
      • ๐Ÿ‘€Watchable Resources
      • โ†”๏ธScalable Resources
      • ๐Ÿ’ŠPodable Resources
      • ๐Ÿ“„Loggable Resources
      • ๐Ÿš’Helper Traits
  • Frameworks
    • Laravel
    • PHP Helm
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Advanced
  2. Create classes for CRDs

Podable Resources

Podable resources are resources that manage pods. You can easily get the pods that are running under the resource and you can control the overall pods inherited by these workload controllers.

For example, Jobs and DaemonSets are some of the kinds that have this behavior.

In PHP K8s, this implementation is a bit tricky and need some configuration on your side:

use RenokiCo\PhpK8s\Contracts\InteractsWithK8sCluster;
use RenokiCo\PhpK8s\Contracts\Podable;
use RenokiCo\PhpK8s\Kinds\K8sResource;
use RenokiCo\PhpK8s\Traits\HasPods;

class GameServerSet extends K8sResource implements InteractsWithK8sCluster, Podable
{
    use HasPods;

    /**
     * Get the selector for the pods that are owned by this resource.
     *
     * @return array
     */
    public function podsSelector(): array
    {
        return [
            'game-server-name' => $this->getName(),
        ];
    }
}
$gameServerSet = new GameServerSet($cluster, [
    'metadata' => [
        'name' => 'some-name', // this is metadata.name
    ],
    'spec' => [
        'template' => [
            'metadata' => [
                'labels' => [
                    'game-server-name' => 'some-name', // this must match with metadata.name
                ],
            ],
            ...
        ],
        ...
    ],
    ...
]);
foreach ($gameServerSet->getPods() as $pod) {
    //
}

As you can see, there is a podsSelector() array where you can define a set of labels that a Pod managed by this resource needs to have in order to ->getPods() to work on it.

GameServerSet::selectPods(function (GameServerSet $gss) {
    // $gssis the current GameServerSet

    return [
        'some-label' => 'some-label-value',
        'some-other-label' => "{$gss->getName()}-custom-name",
    ];
});
PreviousScalable ResourcesNextLoggable Resources

Last updated 3 years ago

Was this helpful?

Alternatively, if you can't control the names and you want to match the labels by each individual resource, you may declare it yourself by calling once a callback that will resolve the label matching for the pod retrieval as explained, for example, in the .

โœจ
๐Ÿ’Š
StatefulSet definition