Skip to content

Instantly share code, notes, and snippets.

View jpbetz's full-sized avatar

Joe Betz jpbetz

  • Google
  • Annapolis, MD
View GitHub Profile
apiVersion: review.gemini.google.com/v1alpha1
kind: RepoWatch
metadata:
name: k8s
spec:
repoURL: https://github.com/kubernetes/kubernetes
githubSecretName: github-pat
review:
gemini:
prompt: |
@jpbetz
jpbetz / kubernetes-code-doc-guidance.md
Last active August 20, 2025 23:30
Kubernetes code documentation guidelines

SIG API Machinery Documentation Improvement Guidelines

Guiding Principles & Quality Standards

This is not just about adding comments; it's about elevating the developer experience for a critical part of the Kubernetes ecosystem. Contributors should aim to create documentation that is clear, comprehensive, and empowers new and existing developers to work with API Machinery effectively.

For a concrete example of the quality standard we are aiming for, please review the changes in pull request #133632, which documents the client-go library. The contents of this PR are also available in the client-go-docs branch for local inspection using git commands.

Our Target Audience: User Personas

@jpbetz
jpbetz / gist:7cc7c6478f8d0e153333c6f09815f52a
Created August 19, 2025 19:36
Tim's diff to add gofmt to hack/update-codegen.sh
diff --git hack/update-codegen.sh hack/update-codegen.sh
index ea899266851..2a2aff11276 100755
--- hack/update-codegen.sh
+++ hack/update-codegen.sh
@@ -153,6 +153,10 @@ function codegen::protobuf() {
kube::log::status "protoc ${PROTOC_VERSION} not found (can install with hack/install-protoc.sh); generating containerized..."
build/run.sh hack/_update-generated-protobuf-dockerized.sh "${apis[@]}"
fi
+
+ git_find -z \
var associativeListParserOld = func() *typed.Parser {
oldParser, err := typed.NewParser(`types:
- name: v1
map:
fields:
- name: list
type:
namedType: associativeList

Adding cross validation support to validation-gen

Overview

This document outlines recommendations for adding cross-field validation capabilities to the existing validation-gen framework in Kubernetes. By enhancing the current tag-based approach with more expressive validation constructs, we can enable complex validation scenarios while maintaining backward compatibility.

Design Principles

  1. Declarative Validation: Express complex validation rules through declarative tags
  2. Type-Safety: Leverage Go's type system for validation definitions

Kubernetes API Validation Rules - Migration Notes

Resource Analysis for Validation Migration

After analyzing the comprehensive validation rules from all Kubernetes resources, I've identified several resource kinds with diverse validation rules, particularly focusing on those with cross-field validations. These resources are prioritized based on both validation diversity and relative simplicity.

Prioritized Resources for Validation Migration

1. Service Resource

Kubernetes API Validation Rules

Introduction

Kubernetes API validation ensures that objects created or updated through the API server meet specific formatting requirements, constraints, and semantic rules before being stored in etcd. Validation occurs in multiple layers:

  1. OpenAPI Schema Validation - Validates basic structure and data types
  2. AdmissionWebhooks - Allow custom validation via webhooks
  3. Built-in Validation - The internal logic specific to each resource type
  4. CEL Validation Rules - For CustomResourceDefinitions
@jpbetz
jpbetz / kubernetes-validations.md
Last active February 4, 2025 22:34
Some high level analysis of kubernetes validations

Admissionregistration API Group Validations (from pkg/apis/admissionregistration/validation/validation.go)

Validation Name JSON Path Validation Type Error Types Cross-field Update-specific
ResourceValidation spec.resources array-unique, non-empty Required, Invalid No No
MatchConditionsValidation spec.matchConditions maxItems=64, unique-names TooMany, Duplicate No No
ValidateParamKind spec.paramKind.apiVersion format=dns1123subdomain Required, Invalid No No
ValidateParamKind spec.paramKind.kind format=dns1035label Required, Invalid No No
MatchResourcesValidation spec.matchResources.matchPolicy enum=Exact,Equivalent Required, NotSupported No No
@jpbetz
jpbetz / squash.sh
Last active January 27, 2025 20:38
#!/bin/bash
# Check if input file is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <input-file>"
exit 1
fi
input_file="$1"
@jpbetz
jpbetz / benchstats.txt
Last active January 23, 2025 16:47
Benchmarking structured-merge-diff for unsetting fields
goos: linux
goarch: amd64
pkg: sigs.k8s.io/structured-merge-diff/v4/fieldpath
cpu: Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
FieldSet/insert-20-8 12.02µ ± ∞ ¹ 11.00µ ± ∞ ¹ ~ (p=1.000 n=1) ²
FieldSet/has-20-8 434.6n ± ∞ ¹ 541.8n ± ∞ ¹ ~ (p=1.000 n=1) ²
FieldSet/serialize-20-8 6.667µ ± ∞ ¹ 8.090µ ± ∞ ¹ ~ (p=1.000 n=1) ²
FieldSet/deserialize-20-8 22.98µ ± ∞ ¹ 21.10µ ± ∞ ¹ ~ (p=1.000 n=1) ²