Skip to content

Commit

Permalink
Init HMCManagement api
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Pavlov <[email protected]>
  • Loading branch information
Kshatrix committed May 27, 2024
1 parent 3199589 commit ad0544f
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 0 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ resources:
kind: HMCDeployment
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
kind: HMCManagement
path: github.com/Mirantis/hmc/api/v1alpha1
version: v1alpha1
version: "3"
64 changes: 64 additions & 0 deletions api/v1alpha1/hmcmanagement_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2024.
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"
)

// 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.

// HMCManagementSpec defines the desired state of HMCManagement
type HMCManagementSpec 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 HMCManagement. Edit hmcmanagement_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

// HMCManagementStatus defines the observed state of HMCManagement
type HMCManagementStatus 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

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

Spec HMCManagementSpec `json:"spec,omitempty"`
Status HMCManagementStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&HMCManagement{}, &HMCManagementList{})
}
89 changes: 89 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "HMCDeployment")
os.Exit(1)
}
if err = (&controller.HMCManagementReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "HMCManagement")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
resources:
- bases/hmc.mirantis.com.hmc.mirantis.com_hmctemplates.yaml
- bases/hmc.mirantis.com.hmc.mirantis.com_hmcdeployments.yaml
- bases/hmc.mirantis.com.hmc.mirantis.com_hmcmanagements.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patches:
Expand All @@ -15,6 +16,7 @@ patches:
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_hmctemplates.yaml
#- path: patches/cainjection_in_hmcdeployments.yaml
#- path: patches/cainjection_in_hmcmanagements.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
27 changes: 27 additions & 0 deletions config/rbac/hmcmanagement_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to edit hmcmanagements.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: hmc
app.kubernetes.io/managed-by: kustomize
name: hmcmanagement-editor-role
rules:
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
resources:
- hmcmanagements
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
resources:
- hmcmanagements/status
verbs:
- get
23 changes: 23 additions & 0 deletions config/rbac/hmcmanagement_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# permissions for end users to view hmcmanagements.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: hmc
app.kubernetes.io/managed-by: kustomize
name: hmcmanagement-viewer-role
rules:
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
resources:
- hmcmanagements
verbs:
- get
- list
- watch
- apiGroups:
- hmc.mirantis.com.hmc.mirantis.com
resources:
- hmcmanagements/status
verbs:
- get
2 changes: 2 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ resources:
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
# if you do not want those helpers be installed with your Project.
- hmcmanagement_editor_role.yaml
- hmcmanagement_viewer_role.yaml
- hmcdeployment_editor_role.yaml
- hmcdeployment_viewer_role.yaml
- hmctemplate_editor_role.yaml
Expand Down
9 changes: 9 additions & 0 deletions config/samples/hmc.mirantis.com_v1alpha1_hmcmanagement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: hmc.mirantis.com.hmc.mirantis.com/v1alpha1
kind: HMCManagement
metadata:
labels:
app.kubernetes.io/name: hmc
app.kubernetes.io/managed-by: kustomize
name: hmcmanagement-sample
spec:
# TODO(user): Add fields here
1 change: 1 addition & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
resources:
- hmc.mirantis.com_v1alpha1_hmctemplate.yaml
- hmc.mirantis.com_v1alpha1_hmcdeployment.yaml
- hmc.mirantis.com_v1alpha1_hmcmanagement.yaml
#+kubebuilder:scaffold:manifestskustomizesamples
62 changes: 62 additions & 0 deletions internal/controller/hmcmanagement_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright 2024.
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 controller

import (
"context"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

hmcmirantiscomv1alpha1 "github.com/Mirantis/hmc/api/v1alpha1"
)

// HMCManagementReconciler reconciles a HMCManagement object
type HMCManagementReconciler struct {
client.Client
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=hmc.mirantis.com.hmc.mirantis.com,resources=hmcmanagements,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=hmc.mirantis.com.hmc.mirantis.com,resources=hmcmanagements/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=hmc.mirantis.com.hmc.mirantis.com,resources=hmcmanagements/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 HMCManagement 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 *HMCManagementReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)

// TODO(user): your logic here

return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *HMCManagementReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&hmcmirantiscomv1alpha1.HMCManagement{}).
Complete(r)
}
Loading

0 comments on commit ad0544f

Please sign in to comment.