Skip to content

Instantly share code, notes, and snippets.

@ihcsim
Last active January 19, 2025 21:24
Show Gist options
  • Save ihcsim/c121799817b96703d7f6e6f70a5cb585 to your computer and use it in GitHub Desktop.
Save ihcsim/c121799817b96703d7f6e6f70a5cb585 to your computer and use it in GitHub Desktop.
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
name: vnodes.virt.dev
spec:
group: virt.dev
names:
kind: VNode
listKind: VNodeList
plural: vnodes
singular: vnode
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: |-
VNode is a virtual machine sandbox optimized to run HPC workloads on Kubernetes.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
type: object
description: VNodeSpec defines the specification for a VNode node.
properties:
staticIP:
type: string
cpu:
type: object
properties:
cores:
type: integer
sockets:
type: integer
threads:
type: integer
memory:
type: object
properties:
guest:
type: string
devices:
type: object
properties:
disks:
type: array
items:
type: object
properties:
disk:
type: object
properties:
bus:
type: string
name:
type: string
interfaces:
type: array
items:
type: object
properties:
macAddress:
type: string
masquerade:
type: object
model:
type: string
name:
type: string
status:
type: object
description: VNodeStatus captures the current status of a VNode node.
properties:
k8sNodeName:
type: string
launchTime:
type: string
phase:
type: string
addresses:
nullable: true
type: array
items:
type: object
properties:
address:
type: string
type:
type: string
conditions:
nullable: true
type: array
items:
type: object
properties:
type:
type: string
status:
type: string
lastHeartbeatTime:
type: string
lastTransitionTime:
type: string
reason:
type: string
message:
type: string
nodeInfo:
type: object
nullable: true
properties:
machineID:
type: string
systemUUID:
type: string
bootID:
type: string
kernelVersion:
type: string
osImage:
type: string
containerRuntimeVersion:
type: string
kubeletVersion:
type: string
kubeProxyVersion:
type: string
operatingSystem:
type: string
architecture:
type: string
type: object
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
name: staticipallocations.virt.dev
spec:
group: virt.dev
names:
kind: StaticIPAllocation
listKind: StaticIPAllocationList
plural: staticipallocations
singular: staticipallocation
scope: Namespaced
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
description: |-
StaticIPAllocation is a list of allocated statis IP addresses. These addresses are not available for use by other resources.
type: object
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
allocations:
type: array
items:
type: object
properties:
ipAddress:
type: string
hwAddress:
type: string
apiVersion: virt.dev/v1alpha1
kind: StaticIPAllocation
metadata:
name: allocated
allocations:
- ipAddress: 192.168.255.100
hwAddress: da:5a:20:f5:e4:ce
- ipAddress: 192.168.255.108
hwAddress: da:5a:20:f5:e4:cf
- ipAddress: 192.168.255.167
hwAddress: da:5a:20:f5:e4:cd
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: vnodes-immutability
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["virt.dev"]
apiVersions: ["v1alpha1"]
operations: ["UPDATE"]
resources: ["vnodes"]
validations:
- expression: "oldObject.spec == object.spec"
message: "VNode spec is immutable"
reason: Invalid
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: vnodes-immutability
spec:
policyName: vnodes-immutability
validationActions: [Deny]
matchResources:
objectSelector:
matchLabels:
virt.dev/immutability: enforced
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: vnodes-unique-static-ip
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: ["virt.dev"]
apiVersions: ["v1alpha1"]
operations: ["CREATE","UPDATE"]
resources: ["vnodes"]
validations:
- expression: "params.allocations.all(e, e.ipAddress != object.spec.staticIP)"
messageExpression: "'conflicting static IP allocation exists: '
+ params.allocations.filter(e, e.ipAddress == object.spec.staticIP)[0].hwAddress
+ '/'
+ params.allocations.filter(e, e.ipAddress == object.spec.staticIP)[0].ipAddress"
reason: Invalid
paramKind:
apiVersion: virt.dev/v1alpha1
kind: StaticIPAllocation
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: vnodes-unique-static-ip
spec:
policyName: vnodes-unique-static-ip
validationActions: [Deny]
paramRef:
name: allocated
namespace: default
parameterNotFoundAction: Deny
apiVersion: virt.dev/v1alpha1
kind: VNode
metadata:
name: vnode2
labels:
virt.dev/immutability: enforced
spec:
staticIP: 192.168.255.100
cpu:
cores: 1
sockets: 1
threads: 1
memory:
guest: 3996Mi
devices:
disks:
- disk:
bus: virtio
name: disk-0
interfaces:
- macAddress: da:5a:20:f5:e4:ce
masquerade: {}
model: virtio
name: default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment