Skip to content

Commit

Permalink
add a new crd device/v1alpha1&v1alpha2/iot and controller, webhook
Browse files Browse the repository at this point in the history
Signed-off-by: Rui-Gan <1171530954@qq.com>
  • Loading branch information
Rui-Gan committed May 23, 2023
1 parent b3ae2c7 commit be06107
Show file tree
Hide file tree
Showing 37 changed files with 15,728 additions and 5 deletions.
8,491 changes: 8,491 additions & 0 deletions charts/yurt-manager/crds/device.openyurt.io_iot.yaml

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions charts/yurt-manager/templates/yurt-manager-auto-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,28 @@ rules:
- patch
- update
- watch
- apiGroups:
- ""
resources:
- configmaps
- services
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- configmaps/status
- services/status
verbs:
- get
- patch
- update
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -351,6 +373,32 @@ rules:
- get
- list
- watch
- apiGroups:
- device.openyurt.io
resources:
- iots
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- device.openyurt.io
resources:
- iots/finalizers
verbs:
- update
- apiGroups:
- device.openyurt.io
resources:
- iots/status
verbs:
- get
- patch
- update
- apiGroups:
- discovery.k8s.io
resources:
Expand Down Expand Up @@ -410,6 +458,26 @@ webhooks:
resources:
- gateways
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: yurt-manager-webhook-service
namespace: {{ .Release.Namespace }}
path: /mutate-device-openyurt-io-v1alpha2-iot
failurePolicy: Fail
name: miot.kb.io
rules:
- apiGroups:
- device.openyurt.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- iots
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down Expand Up @@ -520,6 +588,26 @@ webhooks:
resources:
- gateways
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: yurt-manager-webhook-service
namespace: {{ .Release.Namespace }}
path: /validate-device-openyurt-io-v1alpha2-iot
failurePolicy: Fail
name: viot.kb.io
rules:
- apiGroups:
- device.openyurt.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- iots
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
62 changes: 62 additions & 0 deletions cmd/yurt-manager/app/options/iotcontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright 2023 The OpenYurt 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 options

import (
"errors"

"github.com/openyurtio/openyurt/pkg/controller/iot/config"
"github.com/spf13/pflag"
)

type IoTControllerOptions struct {
*config.IoTControllerConfiguration
}

func NewIoTControllerOptions() *IoTControllerOptions {
return &IoTControllerOptions{
config.NewIoTControllerConfiguration(),
}
}

// AddFlags adds flags related to nodepool for yurt-manager to the specified FlagSet.
func (n *IoTControllerOptions) AddFlags(fs *pflag.FlagSet) {
if n == nil {
return
}
}

// ApplyTo fills up nodepool config with options.
func (o *IoTControllerOptions) ApplyTo(cfg *config.IoTControllerConfiguration) error {
if o == nil {
return nil
}
*cfg = *o.IoTControllerConfiguration
return nil
}

// Validate checks validation of IoTControllerOptions.
func (o *IoTControllerOptions) Validate() []error {
if o == nil {
return nil
}
errs := []error{}
if o.IoTControllerConfiguration == nil {
errs = append(errs, errors.New("IoTControllerConfiguration can not be empty!"))
}
return errs
}
7 changes: 7 additions & 0 deletions cmd/yurt-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type YurtManagerOptions struct {
YurtStaticSetController *YurtStaticSetControllerOptions
YurtAppSetController *YurtAppSetControllerOptions
YurtAppDaemonController *YurtAppDaemonControllerOptions
IoTController *IoTControllerOptions
}

// NewYurtManagerOptions creates a new YurtManagerOptions with a default config.
Expand All @@ -43,6 +44,7 @@ func NewYurtManagerOptions() (*YurtManagerOptions, error) {
YurtStaticSetController: NewYurtStaticSetControllerOptions(),
YurtAppSetController: NewYurtAppSetControllerOptions(),
YurtAppDaemonController: NewYurtAppDaemonControllerOptions(),
IoTController: NewIoTControllerOptions(),
}

return &s, nil
Expand All @@ -55,6 +57,7 @@ func (y *YurtManagerOptions) Flags() cliflag.NamedFlagSets {
y.GatewayController.AddFlags(fss.FlagSet("gateway controller"))
y.YurtStaticSetController.AddFlags(fss.FlagSet("yurtstaticset controller"))
y.YurtAppDaemonController.AddFlags(fss.FlagSet("yurtappdaemon controller"))
y.IoTController.AddFlags(fss.FlagSet("iot controller"))
// Please Add Other controller flags @kadisi

return fss
Expand All @@ -68,6 +71,7 @@ func (y *YurtManagerOptions) Validate() error {
errs = append(errs, y.GatewayController.Validate()...)
errs = append(errs, y.YurtStaticSetController.Validate()...)
errs = append(errs, y.YurtAppDaemonController.Validate()...)
errs = append(errs, y.IoTController.Validate()...)
return utilerrors.NewAggregate(errs)
}

Expand All @@ -85,6 +89,9 @@ func (y *YurtManagerOptions) ApplyTo(c *config.Config) error {
if err := y.YurtAppDaemonController.ApplyTo(&c.ComponentConfig.YurtAppDaemonController); err != nil {
return err
}
if err := y.IoTController.ApplyTo(&c.ComponentConfig.IoTController); err != nil {
return err
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
google.golang.org/grpc v1.54.0
gopkg.in/cheggaaa/pb.v1 v1.0.28
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.22.3
k8s.io/apimachinery v0.22.3
k8s.io/apiserver v0.22.3
Expand Down Expand Up @@ -153,7 +154,6 @@ require (
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.22.2 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.22 // indirect
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/addtoscheme_device_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2023 The OpenYurt 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 apis

import (
version "github.com/openyurtio/openyurt/pkg/apis/device/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, version.SchemeBuilder.AddToScheme)
}
26 changes: 26 additions & 0 deletions pkg/apis/addtoscheme_device_v1alpha2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2023 The OpenYurt 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 apis

import (
version "github.com/openyurtio/openyurt/pkg/apis/device/v1alpha2"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, version.SchemeBuilder.AddToScheme)
}
38 changes: 38 additions & 0 deletions pkg/apis/device/v1alpha1/condition_const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2023 The OpenYurt 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

const (
// ConfigmapAvailableCondition documents the status of the EdgeX configmap.
ConfigmapAvailableCondition IoTConditionType = "ConfigmapAvailable"

ConfigmapProvisioningReason = "ConfigmapProvisioning"

ConfigmapProvisioningFailedReason = "ConfigmapProvisioningFailed"
// ServiceAvailableCondition documents the status of the EdgeX service.
ServiceAvailableCondition IoTConditionType = "ServiceAvailable"

ServiceProvisioningReason = "ServiceProvisioning"

ServiceProvisioningFailedReason = "ServiceProvisioningFailed"
// DeploymentAvailableCondition documents the status of the EdgeX deployment.
DeploymentAvailableCondition IoTConditionType = "DeploymentAvailable"

DeploymentProvisioningReason = "DeploymentProvisioning"

DeploymentProvisioningFailedReason = "DeploymentProvisioningFailed"
)
24 changes: 24 additions & 0 deletions pkg/apis/device/v1alpha1/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2023 The OpenYurt 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

// SetDefaultsIoT set default values for IoT.
func SetDefaultsIoT(obj *IoT) {
if obj.Annotations == nil {
obj.Annotations = make(map[string]string)
}
}
17 changes: 17 additions & 0 deletions pkg/apis/device/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2023 The OpenYurt 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.
*/
// +groupName=device.openyurt.io
package v1alpha1
Loading

0 comments on commit be06107

Please sign in to comment.