Skip to content

Commit

Permalink
add org CRD in helm chart (#116)
Browse files Browse the repository at this point in the history
* add org CRD in helm chart

* layout foundations for CRD with kubebuilder

* remove useless files

* update CRD names

* add generated crd

* applying suggestions

* fix naming issues

* update Dockerfile with copy command for the api package

* update changelog

* add symlink to crd in helm chart and updated crd

* fix symlink

* fix symlink

* Update main.go

Co-authored-by: Quentin Bisson <[email protected]>

* add symlink back

* add finalizer

* Apply suggestions from code review

Co-authored-by: Théo Brigitte <[email protected]>

* regenerate crd

* update sample

* add crds template in chart

* add authorizations for grafanaorganizations in operator rbac

* Update api/v1alpha1/grafanaorganization_types.go

Co-authored-by: Théo Brigitte <[email protected]>

* go format

* Update observability_v1alpha1_grafanaorganization.yaml

Remove labels to make @TheoBrigitte happy

---------

Co-authored-by: QuentinBisson <[email protected]>
Co-authored-by: Théo Brigitte <[email protected]>
  • Loading branch information
3 people authored Oct 15, 2024
1 parent b8fd26f commit 3b383d7
Show file tree
Hide file tree
Showing 14 changed files with 538 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add grafanaOrganization CRD in helm chart.

## [0.7.1] - 2024-10-10

### Fixed
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN go mod download
COPY main.go main.go
COPY pkg/ pkg/
COPY internal/controller/ internal/controller/
COPY api/ api/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
Empty file removed api/.gitkeep
Empty file.
105 changes: 105 additions & 0 deletions api/v1alpha1/grafanaorganization_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
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"
)

const (
// Finalizer needs to follow the format "domain name, a forward slash and the name of the finalizer"
// See https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#finalizers
GrafanaOrganizationFinalizer = "observability.giantswarm.io/grafanaorganization"
)

// GrafanaOrganizationSpec defines the desired state of GrafanaOrganization
type GrafanaOrganizationSpec struct {
// DisplayName is the name displayed when viewing the organization in Grafana. It can be different from the actual org's name.
DisplayName string `json:"displayName"`

// Access rules defines user permissions for interacting with the organization in Grafana.
RBAC *RBAC `json:"rbac,omitempty"`
}

// RBAC defines the RoleBasedAccessControl configuration for the Grafana organization.
// Each fields represents the mapping to a Grafana role:
//
// Admin: full access to the Grafana organization
// Editor: edit resources in the Grafana organization
// Viewer: read only access to the Grafana organization
//
// Each fields holds a list of string which represents values for a specific auth provider org attribute.
// The org attribute is looked up using the `org_attribute_path` which is configured on your Grafana instance, see `https://<YOUR_GRAFANA_INSTANCE>/admin/settings`.
// A user is granted a role when one of its org attribute value is contained within one of the role's values defined here.
// More info on Grafana org attribute and role mapping at [Configure role mapping](https://grafana.com/docs/grafana/latest/setup-grafana/configure-security/configure-authentication/generic-oauth/#configure-role-mapping)
type RBAC struct {
// Admins is a list of user organizations that have admin access to the grafanaorganization.
Admins []string `json:"admins"`

// Editors is a list of user organizations that have editor access to the grafanaorganization.
// +optional
Editors []string `json:"editors"`

// Viewers is a list of user organizations that have viewer access to the grafanaorganization.
// +optional
Viewers []string `json:"viewers"`
}

// GrafanaOrganizationStatus defines the observed state of GrafanaOrganization
type GrafanaOrganizationStatus struct {
// OrgID is the actual organisation ID in grafana.
OrgID string `json:"orgID"`

// DataSources is a list of grafana data sources that are available to the Grafana organization.
DataSources []DataSources `json:"dataSources"`
}

// DataSource defines the name and id for data sources.
type DataSources struct {
// Name is the name of the data source.
Name string `json:"name"`

// ID is the unique id of the data source.
ID string `json:"id"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:subresource:status

// GrafanaOrganization is the Schema describing a Grafana organization. Its lifecycle is managed by the observability-operator.
type GrafanaOrganization struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GrafanaOrganizationSpec `json:"spec,omitempty"`
Status GrafanaOrganizationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Cluster

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

func init() {
SchemeBuilder.Register(&GrafanaOrganization{}, &GrafanaOrganizationList{})
}
36 changes: 36 additions & 0 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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 contains API Schema definitions for the observability v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=observability.giantswarm.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

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

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
169 changes: 169 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.

Loading

0 comments on commit 3b383d7

Please sign in to comment.