Skip to content

Commit

Permalink
Expose installation status and regenerate code
Browse files Browse the repository at this point in the history
* Expose installation status and regenerate code

This change contains a handful of improvements:
 - Logic for the operator to expose ClusterInstallation Status in
   the k8s resource.
 - Logic for the operator to expose any defaults it has used in
   the ClusterInstallation Spec.
 - The necessary go-client code has been generated from the
   ClusterInstallation structs here for use by the provisioning
   server.
 - Minor logging improvements.

* Add .gitattributes file

* Add missing newline in .gitattributes
  • Loading branch information
gabrieljackson authored May 13, 2019
1 parent d037b1b commit 8ee0a88
Show file tree
Hide file tree
Showing 41 changed files with 2,891 additions and 111 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/* linguist-vendored
pkg/client/* linguist-generated
zz_generated* linguist-generated
21 changes: 20 additions & 1 deletion Gopkg.lock

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

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ govet: ## Runs govet against all packages.
generate: ## Runs the kubernetes code-generators and openapi
operator-sdk generate k8s
operator-sdk generate openapi
vendor/k8s.io/code-generator/generate-groups.sh all github.com/mattermost/mattermost-operator/pkg/client github.com/mattermost/mattermost-operator/pkg/apis mattermost:v1alpha1


dep: ## Get dependencies
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Mattermost operator is in alpha, data loss might occur.

## Summary

Mattermost is a scalale, open source collaboration tool. It's written in Golang and React.
Mattermost is a scalable, open source collaboration tool. It's written in Golang and React.

This project offers a Kubernetes Operator for Mattermost to simplify deploying and managing your Mattermost instance.

Expand Down
1 change: 0 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ FROM ${BUILD_IMAGE} AS build
WORKDIR /go/src/github.com/mattermost/mattermost-operator/
COPY . /go/src/github.com/mattermost/mattermost-operator/
RUN cp build/operator-sdk /usr/local/bin/
RUN make generate
RUN make build

# Final Image
Expand Down
13 changes: 6 additions & 7 deletions deploy/crds/mattermost_v1alpha1_clusterinstallation_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,17 @@ spec:
Not included when requesting from the apiserver, only from the Mattermost
Operator API itself. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status'
properties:
paused:
description: Represents whether any actions on the underlying managed
objects are being performed. Only delete actions will be performed.
type: boolean
replicas:
description: Total number of non-terminated pods targeted by this Mattermost
deployment (their labels match the selector).
format: int32
type: integer
required:
- paused
- replicas
state:
description: Represents the running state of the Mattermost instance
type: string
version:
description: The version currently running in the Mattermost instance
type: string
type: object
required:
- spec
Expand Down
44 changes: 31 additions & 13 deletions pkg/apis/mattermost/v1alpha1/clusterinstallation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

////////////////////////////////////////////////////////////////////////////////
// IMPORTANT! //
////////////////////////////////////////////////////////////////////////////////
// Run "make generate" in the root of this repository to regenerate code //
// after modifying this file. //
// Add custom validation using kubebuilder tags: //
// https://book.kubebuilder.io/beyond_basics/generating_crd.html //
////////////////////////////////////////////////////////////////////////////////

// ClusterInstallationSpec defines the desired state of ClusterInstallation
// +k8s:openapi-gen=true
type ClusterInstallationSpec struct {
Expand Down Expand Up @@ -39,20 +48,33 @@ type DatabaseType struct {
ExternalDatabaseSecret string `json:"externalDatabaseSecret,omitempty"`
}

// RunningState is the state of the Mattermost instance
type RunningState string

const (
// Creating is the state when the Mattermost instance is being created
Creating RunningState = "creating"
// Upgrading is the state when the Mattermost instance is being upgraded
Upgrading RunningState = "upgrading"
// Running is the state when the Mattermost instance is fully running
Running RunningState = "running"
)

// ClusterInstallationStatus defines the observed state of ClusterInstallation
// +k8s:openapi-gen=true
type ClusterInstallationStatus struct {
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html

// Represents whether any actions on the underlying managed objects are
// being performed. Only delete actions will be performed.
Paused bool `json:"paused"`
// Represents the running state of the Mattermost instance
// +optional
State RunningState `json:"state,omitempty"`
// Total number of non-terminated pods targeted by this Mattermost deployment
// (their labels match the selector).
Replicas int32 `json:"replicas"`
// +optional
Replicas int32 `json:"replicas,omitempty"`
// The version currently running in the Mattermost instance
// +optional
Version string `json:"version,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ClusterInstallation is the Schema for the clusterinstallations API
Expand All @@ -70,7 +92,7 @@ type ClusterInstallation struct {
// included when requesting from the apiserver, only from the Mattermost
// Operator API itself. More info:
// https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status
Status *ClusterInstallationStatus `json:"status,omitempty"`
Status ClusterInstallationStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -81,7 +103,3 @@ type ClusterInstallationList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterInstallation `json:"items"`
}

func init() {
SchemeBuilder.Register(&ClusterInstallation{}, &ClusterInstallationList{})
}
9 changes: 3 additions & 6 deletions pkg/apis/mattermost/v1alpha1/clusterinstallation_utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"errors"
"fmt"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -33,28 +34,24 @@ const (
// SetDefaults set the missing values in the manifest to the default ones
func (mattermost *ClusterInstallation) SetDefaults() error {
if mattermost.Spec.IngressName == "" {
return fmt.Errorf("need to set the IngressName")
return errors.New("IngressName required, but not set")
}

if mattermost.Spec.Image == "" {
mattermost.Spec.Image = DefaultMattermostImage
}

if mattermost.Spec.Version == "" {
mattermost.Spec.Version = DefaultMattermostVersion
}

if mattermost.Spec.Replicas == 0 {
mattermost.Spec.Replicas = DefaultAmountOfPods
}

if mattermost.Spec.MinioStorageSize == "" {
mattermost.Spec.MinioStorageSize = DefaultMinioStorageSize
}

if len(mattermost.Spec.DatabaseType.Type) == 0 {
mattermost.Spec.DatabaseType.Type = DefaultMattermostDatabaseType
}

return nil
}

Expand Down
35 changes: 29 additions & 6 deletions pkg/apis/mattermost/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,37 @@
package v1alpha1

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

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "mattermost.com", Version: "v1alpha1"}
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: "mattermost.com", Version: "v1alpha1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
var (
//SchemeBuilder is the builder object for the mattermost scheme.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
//AddToScheme is the function to add a mattermost scheme to the serializer.
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ClusterInstallation{},
&ClusterInstallationList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
22 changes: 17 additions & 5 deletions pkg/apis/mattermost/v1alpha1/zz_generated.deepcopy.go

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

33 changes: 2 additions & 31 deletions pkg/apis/mattermost/v1alpha1/zz_generated.openapi.go

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

Loading

0 comments on commit 8ee0a88

Please sign in to comment.