Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds HumioUsers CRD #711

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions api/v1alpha1/humiouser_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2020 Humio https://humio.com

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 (
// HumioUserStateUnknown is the Unknown state of the user
HumioUserStateUnknown = "Unknown"
// HumioUserStateExists is the Exists state of the user
HumioUserStateExists = "Exists"
// HumioUserStateNotFound is the NotFound state of the user
HumioUserStateNotFound = "NotFound"
// HumioUserStateConfigError is the state of the user when user-provided specification results in configuration error, such as non-existent humio cluster
HumioUserStateConfigError = "ConfigError"
)

// HumioUserSpec defines the desired state of HumioUser
type HumioUserSpec struct {
// ManagedClusterName refers to an object of type HumioCluster that is managed by the operator where the Humio
// resources should be created.
// This conflicts with ExternalClusterName.
ManagedClusterName string `json:"managedClusterName,omitempty"`
// ExternalClusterName refers to an object of type HumioExternalCluster where the Humio resources should be created.
// This conflicts with ManagedClusterName.
ExternalClusterName string `json:"externalClusterName,omitempty"`
// Username of the user in humio
Username string `json:"username,omitempty"`
// User ID of the user in humio
ID string `json:"id,omitempty"`
// FullName is the full name of the user
FullName string `json:"fullName,omitempty"`
// Email is the email of the user
Email string `json:"email,omitempty"`
// Company is the compnay of the user
Company string `json:"company,omitempty"`
// CountryCode is the compnay of the user
CountryCode string `json:"countryCode,omitempty"`
// Picture is the url to the user's profile picture
Picture string `json:"picture,omitempty"`
// IsRoot is the root setting for the user
IsRoot bool `json:"isRoot,omitempty"`
// CreatedAt is date when the user was created
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this as part of the spec? I can't think of a reason one would want to set this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen people use it and it is configurable so I think it should be in the spec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What controls will there be around the IsRoot field? Could anyone push a YAML doc to the API server and give themselves root privileges?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that CreatedAt does seem very strange to add (at least to the Spec of the CRD). The go client involved using Users().Add(...) doesn't use it (same for Users().Update(...). The only use of it that I see is to reflect back the CreatedAt timestamp for a user as for when it was created. This does not make sense in HumioUsers.Spec though. If we really want to ensure our k8s CR's store that data, then we can store it in HumioUsers.Status if we really have to, but I'm not sure we really need it. It definitely doesn't belong in the Spec though, since users cannot specify that themselves, but is given by the user upon user-creation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I'll remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What controls will there be around the IsRoot field? Could anyone push a YAML doc to the API server and give themselves root privileges?

Any user that has the ability to create the resource could change the attribute yes but they could also change the cluster resource and change the authentication.

CreatedAt string `json:"createdAt,omitempty"`
}

// HumioUserStatus defines the observed state of HumioUser
type HumioUserStatus struct {
// State reflects the current state of the HumioUser
State string `json:"state,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:path=humiousers,scope=Namespaced
//+kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="The state of the user"
//+operator-sdk:gen-csv:customresourcedefinitions.displayName="Humio User"

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

Spec HumioUserSpec `json:"spec,omitempty"`
Status HumioUserStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&HumioUser{}, &HumioUserList{})
}
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.

105 changes: 105 additions & 0 deletions charts/humio-operator/crds/core.humio.com_humiousers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: humiousers.core.humio.com
labels:
app: 'humio-operator'
app.kubernetes.io/name: 'humio-operator'
app.kubernetes.io/instance: 'humio-operator'
app.kubernetes.io/managed-by: 'Helm'
helm.sh/chart: 'humio-operator-0.19.0'
spec:
group: core.humio.com
names:
kind: HumioUser
listKind: HumioUserList
plural: humiousers
singular: humiouser
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: The state of the user
jsonPath: .status.state
name: State
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: HumioUser is the Schema for the humiousers API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: HumioUserSpec defines the desired state of HumioUser
properties:
company:
description: Company is the compnay of the user
type: string
countryCode:
description: CountryCode is the compnay of the user
type: string
createdAt:
description: CreatedAt is date when the user was created
type: string
email:
description: Email is the email of the user
type: string
externalClusterName:
description: ExternalClusterName refers to an object of type HumioExternalCluster
where the Humio resources should be created. This conflicts with
ManagedClusterName.
type: string
fullName:
description: FullName is the full name of the user
type: string
id:
description: User ID of the user in humio
type: string
isRoot:
description: IsRoot is the root setting for the user
type: boolean
managedClusterName:
description: ManagedClusterName refers to an object of type HumioCluster
that is managed by the operator where the Humio resources should
be created. This conflicts with ExternalClusterName.
type: string
picture:
description: Picture is the url to the user's profile picture
type: string
username:
description: Username of the user in humio
type: string
type: object
status:
description: HumioUserStatus defines the observed state of HumioUser
properties:
state:
description: State reflects the current state of the HumioUser
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
6 changes: 6 additions & 0 deletions charts/humio-operator/templates/operator-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ rules:
- humiorepositories
- humiorepositories/finalizers
- humiorepositories/status
- humiousers
- humiousers/finalizers
- humiousers/status
- humioviews
- humioviews/finalizers
- humioviews/status
Expand Down Expand Up @@ -225,6 +228,9 @@ rules:
- humiorepositories
- humiorepositories/finalizers
- humiorepositories/status
- humiousers
- humiousers/finalizers
- humiousers/status
- humioviews
- humioviews/finalizers
- humioviews/status
Expand Down
Loading