Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Recap API Machinery Deep Dive

Recap API Machinery Deep Dive

Aya (Igarashi) Ozawa

May 17, 2018
Tweet

More Decks by Aya (Igarashi) Ozawa

Other Decks in Technology

Transcript

  1. Recap
    SIG API Machinery
    Deep Dive
    Kubernetes meetup Tokyo #11
    Aya Igarashi @ladicle

    View Slide

  2. @Ladicle
    Aya Igarashi
    Software Engineer - Z Lab Corp.
    Who am I?

    View Slide

  3. Custom Resources
    Demo
    https://github.com/Ladicle/crd-sample

    View Slide

  4. Outline of the Talk
    ★ DeepDive
    Stefan Schimanski
    Senior Software Engineer at Red Hat
    ○ api-serverがapiextensions-apierverに委譲する流れ
    ○ CRDを生成する流れと, raceするbugの紹介
    ○ spec+ statusパターンの推奨 (for subresource)
    ○ structuredなclientコード生成のすゝめ
    ○ OpenAPI v3 schemaによるvalidationの紹介
    ○ 上記のvalidationを利用したpruning
    (schema外のfieldがあった場合は除去 )
    ○ Subresourceの /scaleと /status の紹介
    ○ Versioning, Pruning/Defaulting, Graceful Deletion,
    Server Side Printing Columns, Subresources
    ★ Custom Resources 1.11+ (1.12+)
    https://www.youtube.com/watch?v=XsFH7OEIIvI

    View Slide

  5. Versioning & Validation
    DEEP DIVE

    View Slide

  6. CRD versioning (nop conversion) v1.11
    ○ Design: https://github.com/kubernetes/community/pull/2054/files
    ○ Pull-Request: https://github.com/kubernetes/kubernetes/pull/63830 #ONGOING
    type CustomResourceDefinitionSpec struct {
    ...
    // 将来的にDeprecatedになる.
    Version string
    // 対応するVersionリスト.
    // StoredVersionsリストに含まれているものは削除できない.
    Versions []CustomResourceDefinitionVersion
    }
    type CustomResourceDefinitionVersion struct {
    // v2beta1などのバージョン名.
    Name string
    // REST APIから指定できるようにするかのフラグ.
    Served Boolean
    // Storage(etcd)に保存する時のVersionであるかのフラグ.
    // Versionリストの中で1つのみTrueにする.
    Storage Boolean
    }
    type CustomResourceDefinitionStatus struct {
    ...
    // Storageに保存されているCRのVersionリスト.
    // migrationが完了したらリストから除く.
    StoredVersions []string
    }

    View Slide

  7. CRD versioning v1.12+
    ○ Design: https://github.com/kubernetes/community/pull/2026/files #ONGOING
    type CustomResourceDefinitionVersion struct {
    ...
    Conversion CustomResourceConversion
    }
    // 変更するpathごとにconversion resourceを作成する
    type CustomResourceConversion struct {
    Declarative map[string]CustomResourceDeclarativeConversion
    }
    type CustomResourceDeclarativeConversion struct {
    Rename RenameConversion
    // 右のWebhook用の設定
    External CustomResourceConversionWebhook
    }
    // JsonPath(例: .spec.hoge)形式で指定
    type RenameConversion struct {
    From JsonPath
    To JsonPath
    }
    type CustomResourceExternalConversion struct {
    // 変換先のVersion名リスト.
    To []string
    Webhook ConversionWebhook
    }
    type ConversionWebhook struct {
    // clientとどう通信するかを定義するもの.
    // WebhookのService等を指定する
    ClientConfig WebhookClientConfig
    }
    // 各VersionのValidationにも対応するようだが
    // これの詳細はまだ未定

    View Slide

  8. Validation
    OpenAPI v3 schema & Admission Controllers

    View Slide

  9. Validation using OpenAPI v3 schema
    apiVersion: apiextensions.k8s.io/v1beta1
    kind: CustomResourceDefinition
    metadata:
    name: meetups.kube.tokyo
    ...
    validation:
    openAPIV3Schema:
    properties:
    spec:
    properties:
    eventName:
    type: string
    pattern: '^KubernetesMeetup#\d+$'
    theme:
    type: string
    enum:
    - normal
    - recap
    speakerNames:
    type: array
    items:
    type: string
    capacity:
    type: integer
    default: 10
    minimum: 10
    apiVersion: kube.tokyo/v1
    kind: Meetup
    metadata:
    name: meetup11
    namespace: default
    spec:
    eventName: Kubernetes Meetup Tokyo #11
    theme: recap
    speakerNames:
    - lanMLewis
    - amsy810
    - ladicle
    - nasa9085
    - jyoshise
    - rafiror
    - dtan4
    capacity: 200

    View Slide

  10. Validation using Admission Controllers
    --enable-admission-plugins=DefaultStorageClass,DefaultTolerationSeconds,Mutating
    AdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota
    ● ValidatingAdmissionWebhook
    ○ リソースをValidationするためのWebhook (変更はできない)
    ● MutatingAdmissionWebhook
    ○ リソースのチェックや変更をするための Webhook
    ● Initializers
    ○ リソースを初期化するための metadata.initializers.pendingリストを付与する
    ○ 全ての初期化が終わるまでリソースが作成されない
    etc...

    View Slide

  11. What should I use to validate resources?

    View Slide

  12. WE ARE
    HIRING!

    View Slide

  13. THANK YOU
    For your time & we’ll see you soon
    ladicle

    View Slide