Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/crd/device_example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: sonick8s.io/v1alpha1
kind: NetworkDevice
metadata:
name: example-networkdevice
namespace: default
spec:
os:
type: "LeafRouter"
osVersion: "202305"
firmwareProfile: "test-profile"
operation: "OSUpgrade"
80 changes: 80 additions & 0 deletions config/crd/sonick8s.io_networkdevices.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.19.0
name: networkdevices.sonick8s.io
spec:
group: sonick8s.io
names:
kind: NetworkDevice
listKind: NetworkDeviceList
plural: networkdevices
singular: networkdevice
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: NetworkDevice is a specification for a NetworkDevice resource
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:
description: NetworkDeviceSpec is the spec for a NetworkDevice resource
properties:
firmwareProfile:
type: string
operation:
type: string
operationAction:
type: string
osVersion:
type: string
type:
description: device type of the network device
type: string
type: object
status:
description: NetworkDeviceStatus is the status for a NetworkDevice resource
properties:
lastTransitionTime:
description: last transition time of the network device state
format: date-time
type: string
operationActionState:
description: current operation action state of the network device
type: string
operationState:
description: current operation state of the network device
type: string
osVersion:
description: current OS version of the network device
type: string
state:
description: current state of the network device
type: string
type: object
required:
- spec
type: object
served: true
storage: true
subresources:
status: {}
83 changes: 40 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,53 @@ module k8s.io/sample-controller

go 1.25.0

godebug default=go1.25
// godebug default=go1.25

require (
github.com/davecgh/go-spew v1.1.1
github.com/emicklei/go-restful/v3 v3.12.2
github.com/fxamacker/cbor/v2 v2.9.0
github.com/go-logr/logr v1.4.3
github.com/go-openapi/jsonpointer v0.21.0
github.com/go-openapi/jsonreference v0.20.2
github.com/go-openapi/swag v0.23.0
github.com/google/gnostic-models v0.7.0
github.com/google/go-cmp v0.7.0
github.com/google/uuid v1.6.0
github.com/josharian/intern v1.0.0
github.com/json-iterator/go v1.1.12
github.com/mailru/easyjson v0.7.7
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
github.com/pmezard/go-difflib v1.0.0
github.com/spf13/pflag v1.0.9
github.com/x448/float16 v0.8.4
go.yaml.in/yaml/v2 v2.4.2
go.yaml.in/yaml/v3 v3.0.4
golang.org/x/mod v0.27.0
golang.org/x/net v0.43.0
golang.org/x/oauth2 v0.30.0
golang.org/x/sync v0.16.0
golang.org/x/sys v0.35.0
golang.org/x/term v0.34.0
golang.org/x/text v0.28.0
golang.org/x/time v0.9.0
golang.org/x/tools v0.36.0
google.golang.org/protobuf v1.36.8
gopkg.in/evanphx/json-patch.v4 v4.13.0
gopkg.in/inf.v0 v0.9.1
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.0.0-20251022232024-e681e9f64143
k8s.io/apimachinery v0.0.0-20251022231703-e79daceaa31b
k8s.io/client-go v0.0.0-20251022232504-715199a180dc
k8s.io/code-generator v0.0.0-20251022233416-62789f7b54ab
k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b
k8s.io/klog/v2 v2.130.1
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/mod v0.27.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/term v0.34.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/tools v0.36.0 // indirect
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730
sigs.k8s.io/randfill v1.0.0
sigs.k8s.io/structured-merge-diff/v6 v6.3.0
sigs.k8s.io/yaml v1.6.0
)
37 changes: 37 additions & 0 deletions hack/update-codegen-sonic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}

source "${CODEGEN_PKG}/kube_codegen.sh"

THIS_PKG="k8s.io/sample-controller"

kube::codegen::gen_helpers \
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
"${SCRIPT_ROOT}/pkg/apis"

kube::codegen::gen_client \
--with-watch \
--output-dir "${SCRIPT_ROOT}/pkg/networkdevice/generated" \
--output-pkg "${THIS_PKG}/pkg/networkdevice/generated" \
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
"${SCRIPT_ROOT}/pkg/apis"
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"k8s.io/sample-controller/pkg/signals"
// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
// _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

clientset "k8s.io/sample-controller/pkg/generated/clientset/versioned"
informers "k8s.io/sample-controller/pkg/generated/informers/externalversions"
"k8s.io/sample-controller/pkg/controller"
clientset "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned"
informers "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions"
)

var (
Expand Down Expand Up @@ -66,9 +66,9 @@ func main() {
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
exampleInformerFactory := informers.NewSharedInformerFactory(exampleClient, time.Second*30)

controller := NewController(ctx, kubeClient, exampleClient,
kubeInformerFactory.Apps().V1().Deployments(),
exampleInformerFactory.Samplecontroller().V1alpha1().Foos())
controller := controller.NewDeviceLifecycleController(ctx, kubeClient, exampleClient,
kubeInformerFactory.Core().V1().Nodes(),
exampleInformerFactory.Sonick8s().V1().NetworkDevices())

// notice that there is no need to run Start methods in a separate goroutine. (i.e. go kubeInformerFactory.Start(ctx.done())
// Start method is non-blocking and runs all registered informers in a dedicated goroutine.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2017 The Kubernetes Authors.
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package samplecontroller
package networkdevice

// GroupName is the group name used in this package
const (
GroupName = "samplecontroller.k8s.io"
GroupName = "sonick8s.io"
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2017 The Kubernetes Authors.
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@ limitations under the License.
*/

// +k8s:deepcopy-gen=package
// +groupName=samplecontroller.k8s.io
// +groupName=sonick8s.io

// Package v1alpha1 is the v1alpha1 version of the API.
package v1alpha1
// Package v1 is the v1 version of the API.
package v1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2017 The Kubernetes Authors.
Copyright 2025 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,19 +14,18 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

samplecontroller "k8s.io/sample-controller/pkg/apis/samplecontroller"
networkdevice "k8s.io/sample-controller/pkg/apis/networkdevice"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: samplecontroller.GroupName, Version: "v1alpha1"}

var SchemeGroupVersion = schema.GroupVersion{Group: networkdevice.GroupName, Version: "v1"}
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
Expand All @@ -47,8 +46,8 @@ var (
// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Foo{},
&FooList{},
&NetworkDevice{},
&NetworkDeviceList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
Loading