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

Macros

PreviousVolumesNextCreate classes for CRDs

Last updated 3 years ago

Was this helpful?

Besides the custom callers to call for custom attributes, you may also define your own custom functions, without extending or overwriting classes, using .

In case you are not familiar with Macros, you can see the following example on defining a custom function for the K8sPod instance.

use RenokiCo\PhpK8s\Kinds\K8sPod;

// changeDnsPolicy() does not exist in the code

K8sPod::macro('changeDnsPolicy', function ($policy = 'None') {
    return $this->setSpec('dnsPolicy', $policy);
});

$pod->changeDnsPolicy('ClusterFirst');

$this keyword used within the closure is going to reference the current K8sPod object in this example. You might as well define how many macros you want. The closure can also contain parameters or no parameters at all, based on your needs.

Macros also work with custom callers:

use RenokiCo\PhpK8s\Kinds\K8sPod;

K8sPod::macro('changeMetadata', function (array $metadata) {
    return $this->setMetadata($metadata);
});

$pod->changeMetadata(['name' => 'mysql']);
๐Ÿฐ
Macros