Skip to content

Commit

Permalink
Generate OpenStackConfigVersion API/controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
dprince committed Oct 18, 2021
1 parent d98b49e commit e69fd40
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 0 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ resources:
kind: OpenStackMACAddress
path: github.com/openstack-k8s-operators/osp-director-operator/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: openstack.org
group: osp-director
kind: OpenStackConfigVersion
path: github.com/openstack-k8s-operators/osp-director-operator/api/v1beta1
version: v1beta1
version: "3"
64 changes: 64 additions & 0 deletions api/v1beta1/openstackconfigversion_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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 v1beta1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// OpenStackConfigVersionSpec defines the desired state of OpenStackConfigVersion
type OpenStackConfigVersionSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of OpenStackConfigVersion. Edit openstackconfigversion_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

// OpenStackConfigVersionStatus defines the observed state of OpenStackConfigVersion
type OpenStackConfigVersionStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// OpenStackConfigVersion is the Schema for the openstackconfigversions API
type OpenStackConfigVersion struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec OpenStackConfigVersionSpec `json:"spec,omitempty"`
Status OpenStackConfigVersionStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// OpenStackConfigVersionList contains a list of OpenStackConfigVersion
type OpenStackConfigVersionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []OpenStackConfigVersion `json:"items"`
}

func init() {
SchemeBuilder.Register(&OpenStackConfigVersion{}, &OpenStackConfigVersionList{})
}
89 changes: 89 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ resources:
- bases/osp-director.openstack.org_openstackplaybookgenerators.yaml
- bases/osp-director.openstack.org_openstackephemeralheats.yaml
- bases/osp-director.openstack.org_openstackmacaddresses.yaml
- bases/osp-director.openstack.org_openstackconfigversions.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -28,6 +29,7 @@ patchesStrategicMerge:
#- patches/webhook_in_openstackplaybookgenerators.yaml
#- patches/webhook_in_openstackephemeralheats.yaml
#- patches/webhook_in_openstackmacaddresses.yaml
#- patches/webhook_in_openstackconfigversions.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -43,6 +45,7 @@ patchesStrategicMerge:
#- patches/cainjection_in_openstackplaybookgenerators.yaml
- patches/cainjection_in_openstackephemeralheats.yaml
#- patches/cainjection_in_openstackmacaddresses.yaml
#- patches/cainjection_in_openstackconfigversions.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: openstackconfigversions.osp-director.openstack.org
14 changes: 14 additions & 0 deletions config/crd/patches/webhook_in_openstackconfigversions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: openstackconfigversions.osp-director.openstack.org
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
24 changes: 24 additions & 0 deletions config/rbac/openstackconfigversion_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# permissions for end users to edit openstackconfigversions.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: openstackconfigversion-editor-role
rules:
- apiGroups:
- osp-director.openstack.org
resources:
- openstackconfigversions
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- osp-director.openstack.org
resources:
- openstackconfigversions/status
verbs:
- get
20 changes: 20 additions & 0 deletions config/rbac/openstackconfigversion_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# permissions for end users to view openstackconfigversions.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: openstackconfigversion-viewer-role
rules:
- apiGroups:
- osp-director.openstack.org
resources:
- openstackconfigversions
verbs:
- get
- list
- watch
- apiGroups:
- osp-director.openstack.org
resources:
- openstackconfigversions/status
verbs:
- get
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: osp-director.openstack.org/v1beta1
kind: OpenStackConfigVersion
metadata:
name: openstackconfigversion-sample
spec:
# Add fields here
foo: bar
63 changes: 63 additions & 0 deletions controllers/openstackconfigversion_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
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 controllers

import (
"context"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

ospdirectorv1beta1 "github.com/openstack-k8s-operators/osp-director-operator/api/v1beta1"
)

// OpenStackConfigVersionReconciler reconciles a OpenStackConfigVersion object
type OpenStackConfigVersionReconciler struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=osp-director.openstack.org,resources=openstackconfigversions,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=osp-director.openstack.org,resources=openstackconfigversions/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=osp-director.openstack.org,resources=openstackconfigversions/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
// the OpenStackConfigVersion object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
func (r *OpenStackConfigVersionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = r.Log.WithValues("openstackconfigversion", req.NamespacedName)

// your logic here

return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *OpenStackConfigVersionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&ospdirectorv1beta1.OpenStackConfigVersion{}).
Complete(r)
}
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ func main() {
}
}

if err = (&controllers.OpenStackConfigVersionReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("OpenStackConfigVersion"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OpenStackConfigVersion")
os.Exit(1)
}
// +kubebuilder:scaffold:builder

setupLog.Info("starting manager")
Expand Down

0 comments on commit e69fd40

Please sign in to comment.