Skip to content

Commit

Permalink
make schema paths optional
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Bernal <[email protected]>
  • Loading branch information
jgbernalp committed Oct 23, 2023
1 parent 07d862d commit 6223f56
Show file tree
Hide file tree
Showing 19 changed files with 149 additions and 139 deletions.
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ resources:
namespaced: true
controller: true
domain: perses.dev
group: observability
group:
kind: Perses
path: github.com/perses/perses-operator/api/v1alpha1
version: v1alpha1
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ make deploy IMG=<some-registry>/perses-operator:tag
4. Install a CRD instance

```sh
kubectl apply -f config/samples/observability_v1alpha1_perses.yaml --namespace default
kubectl apply -f config/samples/v1alpha1_perses.yaml --namespace default
```

5. Install a CRD instance

```sh
kubectl delete -f config/samples/observability_v1alpha1_perses.yaml --namespace default
kubectl delete -f config/samples/v1alpha1_perses.yaml --namespace default
```

### Uninstall CRDs
Expand Down Expand Up @@ -83,13 +83,13 @@ PERSES_IMAGE=docker.io/persesdev/perses:latest make install run
2. Install a CRD instance

```sh
kubectl apply -f config/samples/observability_v1alpha1_perses.yaml --namespace default
kubectl apply -f config/samples/v1alpha1_perses.yaml --namespace default
```

3. Uninstall the CRD instance

```sh
kubectl delete -f config/samples/observability_v1alpha1_perses.yaml --namespace default
kubectl delete -f config/samples/v1alpha1_perses.yaml --namespace default
```

### Modifying the API definitions
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ 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
// Package v1alpha1 contains API Schema definitions for the v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=observability.perses.dev
// +groupName=perses.dev
package v1alpha1

import (
Expand All @@ -26,7 +26,7 @@ import (

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

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
13 changes: 7 additions & 6 deletions api/v1alpha1/perses_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +kubebuilder:validation:Enum=json,yaml
// +kubebuilder:validation:Enum=json;yaml
type FileExtension string

type File struct {
Expand All @@ -35,21 +35,22 @@ type Database struct {
}

type Schemas struct {
// +kubebuilder:default:="/etc/perses/schemas/panels"
// +kubebuilder:validation:optional
PanelsPath string `json:"panels_path,omitempty" yaml:"panels_path,omitempty"`
// +kubebuilder:default:="/etc/perses/schemas/queries"
// +kubebuilder:validation:optional
QueriesPath string `json:"queries_path,omitempty" yaml:"queries_path,omitempty"`
// +kubebuilder:default:="/etc/perses/schemas/datasources"
// +kubebuilder:validation:optional
DatasourcesPath string `json:"datasources_path,omitempty" yaml:"datasources_path,omitempty"`
// +kubebuilder:default:="/etc/perses/schemas/variables"
// +kubebuilder:validation:optional
VariablesPath string `json:"variables_path,omitempty" yaml:"variables_path,omitempty"`
// +kubebuilder:default:="5m"
// +kubebuilder:validation:optional
Interval time.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
}

// TODO: import this from https://github.com/perses/perses/blob/main/internal/api/config/config.go#L51
type PersesConfig struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// +kubebuilder:validation:optional
Readonly bool `json:"readonly" yaml:"readonly"`
Database Database `json:"database" yaml:"database"`
Schemas Schemas `json:"schemas" yaml:"schemas"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
name: perses.observability.perses.dev
name: perses.perses.dev
spec:
group: observability.perses.dev
group: perses.dev
names:
kind: Perses
listKind: PersesList
Expand Down Expand Up @@ -43,6 +43,9 @@ spec:
file:
properties:
extension:
enum:
- json
- yaml
type: string
folder:
type: string
Expand Down
4 changes: 2 additions & 2 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/observability.perses.dev_perses.yaml
- bases/perses.dev_perses.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -18,4 +18,4 @@ patchesStrategicMerge:

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
- kustomizeconfig.yaml
2 changes: 1 addition & 1 deletion config/crd/patches/cainjection_in_perses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: perses.observability.perses.dev
name: perses.perses.dev
4 changes: 2 additions & 2 deletions config/crd/patches/webhook_in_perses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: perses.observability.perses.dev
name: perses.perses.dev
spec:
conversion:
strategy: Webhook
Expand All @@ -13,4 +13,4 @@ spec:
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
- v1
36 changes: 18 additions & 18 deletions config/rbac/perses_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: perses-editor-role
rules:
- apiGroups:
- observability.perses.dev
resources:
- perses
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- observability.perses.dev
resources:
- perses/status
verbs:
- get
- apiGroups:
- perses.dev
resources:
- perses
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- perses.dev
resources:
- perses/status
verbs:
- get
28 changes: 14 additions & 14 deletions config/rbac/perses_viewer_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ metadata:
app.kubernetes.io/managed-by: kustomize
name: perses-viewer-role
rules:
- apiGroups:
- observability.perses.dev
resources:
- perses
verbs:
- get
- list
- watch
- apiGroups:
- observability.perses.dev
resources:
- perses/status
verbs:
- get
- apiGroups:
- perses.dev
resources:
- perses
verbs:
- get
- list
- watch
- apiGroups:
- perses.dev
resources:
- perses/status
verbs:
- get
106 changes: 53 additions & 53 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- apps
resources:
- deployments
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
- apiGroups:
- observability.perses.dev
resources:
- perses
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- observability.perses.dev
resources:
- perses/finalizers
verbs:
- update
- apiGroups:
- observability.perses.dev
resources:
- perses/status
verbs:
- get
- patch
- update
- apiGroups:
- apps
resources:
- deployments
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
- apiGroups:
- perses.dev
resources:
- perses
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- perses.dev
resources:
- perses/finalizers
verbs:
- update
- apiGroups:
- perses.dev
resources:
- perses/status
verbs:
- get
- patch
- update
2 changes: 1 addition & 1 deletion config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Append samples you want in your CSV to this file as resources ##
resources:
- observability_v1alpha1_perses.yaml
- v1alpha1_perses.yaml
#+kubebuilder:scaffold:manifestskustomizesamples
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: observability.perses.dev/v1alpha1
apiVersion: perses.dev/v1alpha1
kind: Perses
metadata:
labels:
Expand Down
13 changes: 7 additions & 6 deletions controllers/configmap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"time"

observabilityv1alpha1 "github.com/perses/perses-operator/api/v1alpha1"
"github.com/perses/perses-operator/api/v1alpha1"
common "github.com/perses/perses-operator/internal/perses/common"
subreconciler "github.com/perses/perses-operator/internal/subreconciler"
logger "github.com/sirupsen/logrus"
Expand All @@ -37,7 +37,7 @@ import (
var cmlog = logger.WithField("module", "configmap_controller")

func (r *PersesReconciler) reconcileConfigMap(ctx context.Context, req ctrl.Request) (*ctrl.Result, error) {
perses := &observabilityv1alpha1.Perses{}
perses := &v1alpha1.Perses{}

if r, err := r.getLatestPerses(ctx, req, perses); subreconciler.ShouldHaltOrRequeue(r, err) {
return r, err
Expand All @@ -48,8 +48,7 @@ func (r *PersesReconciler) reconcileConfigMap(ctx context.Context, req ctrl.Requ
found := &corev1.ConfigMap{}
err := r.Get(ctx, types.NamespacedName{Name: configName, Namespace: perses.Namespace}, found)
if err != nil && apierrors.IsNotFound(err) {

cm, err := configMapForPerses(r, perses)
cm, err := createPersesConfigMap(r, perses)
if err != nil {
cmlog.Error(err, "Failed to define new ConfigMap resource for perses")

Expand All @@ -74,15 +73,17 @@ func (r *PersesReconciler) reconcileConfigMap(ctx context.Context, req ctrl.Requ
}

return subreconciler.RequeueWithDelay(time.Minute)
} else if err != nil {
}

if err != nil {
cmlog.Error(err, "Failed to get Deployment")
return subreconciler.RequeueWithError(err)
}

return subreconciler.ContinueReconciling()
}

func configMapForPerses(r *PersesReconciler, perses *observabilityv1alpha1.Perses) (*corev1.ConfigMap, error) {
func createPersesConfigMap(r *PersesReconciler, perses *v1alpha1.Perses) (*corev1.ConfigMap, error) {
configName := common.GetConfigName(perses.Name)
ls := common.LabelsForPerses(configName, perses.Name)

Expand Down
Loading

0 comments on commit 6223f56

Please sign in to comment.