Skip to content

Commit

Permalink
Merge pull request #41 from jmencak/crd-v1
Browse files Browse the repository at this point in the history
Moving Tuned to API v1.
  • Loading branch information
openshift-merge-robot committed Feb 21, 2019
2 parents e5b0fbc + 634110b commit b5c14de
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 43 deletions.
2 changes: 1 addition & 1 deletion assets/tuned/07-cr-tuned.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: tuned.openshift.io/v1alpha1
apiVersion: tuned.openshift.io/v1
kind: Tuned
metadata:
name: default
Expand Down
12 changes: 11 additions & 1 deletion manifests/02-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ kind: CustomResourceDefinition
metadata:
name: tuneds.tuned.openshift.io
spec:
# group name to use for REST API: /apis/<group>/<version>
group: tuned.openshift.io
names:
# kind is normally the CamelCased singular type. Your resource manifests use this.
kind: Tuned
listKind: TunedList
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
plural: tuneds
# singular name to be used as an alias on the CLI and for display
singular: tuned
scope: Namespaced
version: v1alpha1
# list of versions supported by this CustomResourceDefinition
versions:
- name: v1
# Each version can be enabled/disabled by Served flag.
served: true
# One and only one version must be marked as the storage version.
storage: true
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package apis

import (
"github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1alpha1"
"github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
AddToSchemes = append(AddToSchemes, v1.SchemeBuilder.AddToScheme)
}
4 changes: 4 additions & 0 deletions pkg/apis/tuned/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package v1 contains API Schema definitions for the tuned v1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=tuned.openshift.io
package v1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// NOTE: Boilerplate only. Ignore this file.

// Package v1alpha1 contains API Schema definitions for the tuned v1alpha1 API group
// Package v1 contains API Schema definitions for the tuned v1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=tuned.openshift.io
package v1alpha1
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -12,7 +12,7 @@ import (

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

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
package v1alpha1
package v1

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions pkg/apis/tuned/v1alpha1/doc.go

This file was deleted.

24 changes: 12 additions & 12 deletions pkg/controller/tuned/tuned_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
tunedv1alpha1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1alpha1"
tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
ntoconfig "github.com/openshift/cluster-node-tuning-operator/pkg/config"
"github.com/openshift/cluster-node-tuning-operator/pkg/manifests"

Expand Down Expand Up @@ -50,15 +50,15 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
}

// Watch for changes to primary resource Tuned
err = c.Watch(&source.Kind{Type: &tunedv1alpha1.Tuned{}}, &handler.EnqueueRequestForObject{})
err = c.Watch(&source.Kind{Type: &tunedv1.Tuned{}}, &handler.EnqueueRequestForObject{})
if err != nil {
return err
}

// Watch for changes to secondary resource DaemonSet and requeue the owner Tuned
err = c.Watch(&source.Kind{Type: &appsv1.DaemonSet{}}, &handler.EnqueueRequestForOwner{
IsController: true,
OwnerType: &tunedv1alpha1.Tuned{},
OwnerType: &tunedv1.Tuned{},
})
if err != nil {
return err
Expand All @@ -85,7 +85,7 @@ type ReconcileTuned struct {
cfgv1client *configv1client.ConfigV1Client
}

func (r *ReconcileTuned) syncServiceAccount(tuned *tunedv1alpha1.Tuned) error {
func (r *ReconcileTuned) syncServiceAccount(tuned *tunedv1.Tuned) error {
glog.V(1).Infof("syncServiceAccount()")
saManifest, err := r.manifestFactory.TunedServiceAccount()
if err != nil {
Expand Down Expand Up @@ -116,7 +116,7 @@ func (r *ReconcileTuned) syncServiceAccount(tuned *tunedv1alpha1.Tuned) error {
return nil
}

func (r *ReconcileTuned) syncClusterRole(tuned *tunedv1alpha1.Tuned) error {
func (r *ReconcileTuned) syncClusterRole(tuned *tunedv1.Tuned) error {
glog.V(1).Infof("syncClusterRole()")
crManifest, err := r.manifestFactory.TunedClusterRole()
if err != nil {
Expand Down Expand Up @@ -147,7 +147,7 @@ func (r *ReconcileTuned) syncClusterRole(tuned *tunedv1alpha1.Tuned) error {
return nil
}

func (r *ReconcileTuned) syncClusterRoleBinding(tuned *tunedv1alpha1.Tuned) error {
func (r *ReconcileTuned) syncClusterRoleBinding(tuned *tunedv1.Tuned) error {
glog.V(1).Infof("syncClusterRoleBinding()")
crbManifest, err := r.manifestFactory.TunedClusterRoleBinding()
if err != nil {
Expand Down Expand Up @@ -178,9 +178,9 @@ func (r *ReconcileTuned) syncClusterRoleBinding(tuned *tunedv1alpha1.Tuned) erro
return nil
}

func (r *ReconcileTuned) syncClusterConfigMap(f func(tuned []tunedv1alpha1.Tuned) (*corev1.ConfigMap, error), tuned *tunedv1alpha1.Tuned) error {
func (r *ReconcileTuned) syncClusterConfigMap(f func(tuned []tunedv1.Tuned) (*corev1.ConfigMap, error), tuned *tunedv1.Tuned) error {
glog.V(1).Infof("syncClusterConfigMap()")
tunedList := &tunedv1alpha1.TunedList{}
tunedList := &tunedv1.TunedList{}
listOps := &client.ListOptions{Namespace: tuned.Namespace}
err := r.client.List(context.TODO(), listOps, tunedList)
if err != nil {
Expand Down Expand Up @@ -216,7 +216,7 @@ func (r *ReconcileTuned) syncClusterConfigMap(f func(tuned []tunedv1alpha1.Tuned
return nil
}

func (r *ReconcileTuned) syncDaemonSet(tuned *tunedv1alpha1.Tuned) error {
func (r *ReconcileTuned) syncDaemonSet(tuned *tunedv1.Tuned) error {
glog.V(1).Infof("syncDaemonSet()")
dsManifest, err := r.manifestFactory.TunedDaemonSet()
if err != nil {
Expand Down Expand Up @@ -267,7 +267,7 @@ func createCustomResource(mgr manager.Manager) error {
return nil
}

func addOwnerReference(meta *metav1.ObjectMeta, tuned *tunedv1alpha1.Tuned) []metav1.OwnerReference {
func addOwnerReference(meta *metav1.ObjectMeta, tuned *tunedv1.Tuned) []metav1.OwnerReference {
var isController bool
if tuned.Name == "default" {
isController = true
Expand All @@ -285,7 +285,7 @@ func addOwnerReference(meta *metav1.ObjectMeta, tuned *tunedv1alpha1.Tuned) []me
}

ownerReference := metav1.OwnerReference{
APIVersion: tunedv1alpha1.SchemeGroupVersion.String(),
APIVersion: tunedv1.SchemeGroupVersion.String(),
Kind: "Tuned",
Name: tuned.Name,
UID: tuned.UID,
Expand All @@ -309,7 +309,7 @@ func (r *ReconcileTuned) Reconcile(request reconcile.Request) (reconcile.Result,
reconcileResult := reconcile.Result{RequeueAfter: reconcilePeriod}

// Fetch the Tuned instance
tunedInstance := &tunedv1alpha1.Tuned{}
tunedInstance := &tunedv1.Tuned{}
err := r.client.Get(context.TODO(), request.NamespacedName, tunedInstance)
if err != nil {
glog.Errorf("Couldn't get tunedInstance(): %v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/manifests/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"

"github.com/golang/glog"
tunedv1alpha1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1alpha1"
tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
ntoconfig "github.com/openshift/cluster-node-tuning-operator/pkg/config"
)

Expand Down Expand Up @@ -76,7 +76,7 @@ func (f *Factory) TunedClusterRoleBinding() (*rbacv1.ClusterRoleBinding, error)
return crb, nil
}

func (f *Factory) TunedConfigMapProfiles(tunedArray []tunedv1alpha1.Tuned) (*corev1.ConfigMap, error) {
func (f *Factory) TunedConfigMapProfiles(tunedArray []tunedv1.Tuned) (*corev1.ConfigMap, error) {
cm, err := NewConfigMap(MustAssetReader(TunedConfigMapProfiles))
if err != nil {
return nil, err
Expand All @@ -96,10 +96,10 @@ func (f *Factory) TunedConfigMapProfiles(tunedArray []tunedv1alpha1.Tuned) (*cor
return cm, nil
}

func (f *Factory) TunedConfigMapRecommend(tunedArray []tunedv1alpha1.Tuned) (*corev1.ConfigMap, error) {
func (f *Factory) TunedConfigMapRecommend(tunedArray []tunedv1.Tuned) (*corev1.ConfigMap, error) {
var (
sb strings.Builder
aRecommendAll []tunedv1alpha1.TunedRecommend
aRecommendAll []tunedv1.TunedRecommend
)
cm, err := NewConfigMap(MustAssetReader(TunedConfigMapRecommend))
if err != nil {
Expand Down Expand Up @@ -142,7 +142,7 @@ func (f *Factory) TunedDaemonSet() (*appsv1.DaemonSet, error) {
return ds, nil
}

func (f *Factory) TunedCustomResource() (*tunedv1alpha1.Tuned, error) {
func (f *Factory) TunedCustomResource() (*tunedv1.Tuned, error) {
cr, err := NewTuned(MustAssetReader(TunedCustomResource))
if err != nil {
return nil, err
Expand Down Expand Up @@ -190,15 +190,15 @@ func NewDaemonSet(manifest io.Reader) (*appsv1.DaemonSet, error) {
return &ds, nil
}

func NewTuned(manifest io.Reader) (*tunedv1alpha1.Tuned, error) {
o := tunedv1alpha1.Tuned{}
func NewTuned(manifest io.Reader) (*tunedv1.Tuned, error) {
o := tunedv1.Tuned{}
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&o); err != nil {
return nil, err
}
return &o, nil
}

func toRecommendLine(match *tunedv1alpha1.TunedMatch) string {
func toRecommendLine(match *tunedv1.TunedMatch) string {
var (
sb strings.Builder
labelsFile string
Expand Down Expand Up @@ -245,7 +245,7 @@ func toRecommendConf(recommend []tunedRecommend, i *int) string {
return sb.String()
}

func matchWalk(match *tunedv1alpha1.TunedMatch, p tunedRecommend) []tunedRecommend {
func matchWalk(match *tunedv1.TunedMatch, p tunedRecommend) []tunedRecommend {
var (
sb strings.Builder
aRecommend []tunedRecommend
Expand All @@ -271,13 +271,13 @@ func matchWalk(match *tunedv1alpha1.TunedMatch, p tunedRecommend) []tunedRecomme
return aRecommend
}

func recommendWalk(r *tunedv1alpha1.TunedRecommend) []tunedRecommend {
func recommendWalk(r *tunedv1.TunedRecommend) []tunedRecommend {
var aRecommend []tunedRecommend

if r.Profile != nil {
if len(r.Match) == 0 {
// Empty catch-all profile with no node/pod labels
sRecommend := toRecommendLine(&tunedv1alpha1.TunedMatch{})
sRecommend := toRecommendLine(&tunedv1.TunedMatch{})
aRecommend = append(aRecommend, tunedRecommend{Profile: *r.Profile, Data: sRecommend})
}
for _, m := range r.Match {
Expand All @@ -296,7 +296,7 @@ func recommendWalk(r *tunedv1alpha1.TunedRecommend) []tunedRecommend {
return aRecommend
}

func tunedConfigMapProfiles(tuned *tunedv1alpha1.Tuned, m map[string]string) {
func tunedConfigMapProfiles(tuned *tunedv1.Tuned, m map[string]string) {
if tuned.Spec.Profile != nil {
for _, v := range tuned.Spec.Profile {
if v.Name != nil && v.Data != nil {
Expand Down
Loading

0 comments on commit b5c14de

Please sign in to comment.