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
65 changes: 65 additions & 0 deletions artifacts/examples/crd-sonic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: sonicdaemonsetdeployments.sonic.k8s.io
# for more information on the below annotation, please see
# https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/2337-k8s.io-group-protection/README.md
annotations:
"api-approved.kubernetes.io": "unapproved, experimental-only; please get an approval from Kubernetes API reviewers if you're trying to develop a CRD in the *.k8s.io or *.kubernetes.io groups"
spec:
group: sonick8s.io
versions:
- name: v1alpha1
served: true
storage: true
schema:
# schema used for validation
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
scopeType:
type: string
scopeValue:
type: string
daemonSetType:
type: string
daemonSetVersion:
type: string
pause:
type: boolean
status:
type: object
properties:
desiredDaemonSetCount:
type: integer
currentDaemonSetCount:
type: integer
daemonSetList:
type: array
items:
type: object
properties:
daemonSetName:
type: string
daemonSetVersion:
type: string
updateInProgressDaemonSetList:
type: array
items:
type: object
properties:
daemonSetName:
type: string
daemonSetVersion:
type: string
# subresources for the custom resource
subresources:
# enables the status subresource
status: {}
names:
kind: SonicDaemonSetDeployment
plural: sonicdaemonsetdeployments
scope: Namespaced
6 changes: 6 additions & 0 deletions artifacts/examples/example-sonic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: sonic.k8s.io/v1alpha1
kind: DcDaemonSet
metadata:
name: example-dc-daemonset
spec:
daemonsetVersion: telemetry-20220531.24
36 changes: 36 additions & 0 deletions hack/update-codegen-sonic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/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)}

# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
"${CODEGEN_PKG}/generate-groups.sh" "deepcopy,client,informer,lister" \
k8s.io/sample-controller/pkg/sonick8s/generated \
k8s.io/sample-controller/pkg/apis \
sonick8s:v1alpha1 \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt

# To use your own boilerplate text append:
# --go-header-file "${SCRIPT_ROOT}"/hack/custom-boilerplate.go.txt
22 changes: 22 additions & 0 deletions pkg/apis/sonick8s/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
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.
*/

package samplecontroller

// GroupName is the group name used in this package
const (
GroupName = "samplecontroller.k8s.io"
)
21 changes: 21 additions & 0 deletions pkg/apis/sonick8s/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
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.
*/

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

// Package v1alpha1 is the v1alpha1 version of the API.
package v1alpha1 // import "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1"
53 changes: 53 additions & 0 deletions pkg/apis/sonick8s/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
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.
*/

package v1alpha1

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

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

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
// SchemeBuilder initializes a scheme builder
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is a global function that registers this API group & version to a scheme
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&DcDaemonSet{},
&DcDaemonSetList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
67 changes: 67 additions & 0 deletions pkg/apis/sonick8s/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
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.
*/

package v1alpha1

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

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// SonicDaemonSetDeployment is a specification for a SonicDaemonSetDeployment resource
type SonicDaemonSetDeployment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SonicDaemonSetDeploymentSpec `json:"spec"`
Status SonicDaemonSetDeploymentStatus `json:"status"`
}

// SonicDaemonSetDeploymentSpec is the spec for a SonicDaemonSetDeployment resource
type SonicDaemonSetDeploymentSpec struct {
// ScopeType: datacenter or region
ScopeType string `json:"scopeType"`
ScopeValue string `json:"scopeValue"`
// sonic feature such as telemetry, snmp, etc
DaemonSetType string `json:"daemonSetType"`
DaemonSetVersion string `json:"daemonSetVersion"`
Pause bool `json:"pause"`
}

// SonicDaemonSetDeploymentStatus is the status for a SonicDaemonSetDeployment resource
type SonicDaemonSetDeploymentStatus struct {
DesiredDaemonSetCount int `json:"desiredDaemonSetCount"`
CurrentDaemonSetCount int `json:"currentDaemonSetCount"`
DaemonsetList []DaemonSetItem `json:"daemonSetList"`
UpdateInProgressDaemonsetList []DaemonSetItem `json:"updateInProgressDaemonSetList"`
}

type DaemonSetItem struct {
DaemonSetName string `json:"daemonSetName"`
DaemonSetVersion string `json:"daemonSetVersion"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// SonicDaemonSetDeploymentList is a list of SonicDaemonSetDeployment resources
type SonicDaemonSetDeploymentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []SonicDaemonSetDeployment `json:"items"`
}