Skip to content

Commit

Permalink
Pr 22 merge (#158)
Browse files Browse the repository at this point in the history
* kubebuilder init --domain azure --license none

* kubebuilder create api --group service --version v1alpha1 --kind Storage

* kubebuilder create api --group service --version v1alpha1 --kind CosmosDB

* Add MIT License

* Initial codes to support Azure Storage Account

* Add development docs

* Remove the storage account name from the spec

* Sync additional resources for Azure storage account

1. Create a secret based on storage account credentials
2. Add the global config

* Upgrade kubebuilder to 2.0.0-beta.0 and controller-runtime to v0.2.0-beta.4

* Copy pkg in Dockerfile

* Update controller-gen and make manifests

* Add prefix "Storage" for storage_types

* feature: add redis cache service

* Ignore the NotFound error when deleting resources

* Requeue the request if the deployment is not complete

* feature: add cosmosdb service

* Refine the logic of updating additional resources and output

* Deploy operator on a remote cluster

* add a sample app deployment yaml

* Generate assets for the templates

* Requeue after 30 seconds to avoid too many requests

Ignore the NotFound error when deleting cosmosdb

* Fix a bug of missing capacity of rediscache template

* fix: judge whether resources need to be updated
With adding generation in status, we can judge whether resources need to be updated.

Co-authored-by: Bin Xia <binxi@microsoft.com>

* Add docs to run the demo

* Update manager-role to operate secrets

Workaround: the rule should be appended. But I don't know how for now.
The workaround is to copy config/rbac/role.yaml and add the new rule.
Should be fixed in future.

* fix(Makefile): rename the target from "generate" to "generate-template" to avoid conflict

* Refactoring data focused operators.  Storage currently working though it needs cleanup

* Added deepcopy generated code

* CosmosDB deploy working

* Detailing current implementation of CosmosDB Create parameters

* Removing TestTags

* Redis cache now deploys

* Cleaned up code and removed references to v1alpha1

* Updating controllers logging calls

Co-authored-by: Chris Risner <github@chrisrisner.com>
Co-authored-by: Bin Xia <binxi@microsoft.com>
  • Loading branch information
3 people authored and frodopwns committed Aug 29, 2019
1 parent c22f7c0 commit f676751
Show file tree
Hide file tree
Showing 49 changed files with 4,681 additions and 5 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export GO111MODULE=on
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ default.etcd

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

bin/
vendor/
coverage.txt
report.xml
cover.html
Expand Down
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Image URL to use all building/pushing image targets


# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
Expand Down Expand Up @@ -70,6 +79,9 @@ docker-build:
docker-push:
docker push ${IMG}

# Build and Push the docker image
build-and-push: docker-build docker-push

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
Expand All @@ -80,6 +92,14 @@ else
CONTROLLER_GEN=$(shell which controller-gen)
endif

.PHONY: install-bindata
install-bindata:
go get -u github.com/jteeuwen/go-bindata/...

.PHONE:
generate-template:
go-bindata -pkg template -prefix pkg/template/assets/ -o pkg/template/templates.go pkg/template/assets/

create-kindcluster:
ifeq (,$(shell kind get clusters))
@echo "no kind cluster"
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ version: "2"
domain: microsoft.com
repo: github.com/Azure/azure-service-operator
resources:
- group: service
version: v1
kind: Storage
- group: service
version: v1
kind: CosmosDB
- group: service
version: v1
kind: RedisCache
- group: azure
version: v1
kind: Eventhub
Expand Down
136 changes: 136 additions & 0 deletions api/v1/cosmosdb_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
MIT License
Copyright (c) Microsoft Corporation. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
*/

package v1

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.

// CosmosDBSpec defines the desired state of CosmosDB
type CosmosDBSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:validation:MinLength=0

Location string `json:"location,omitempty"`
ResourceGroupName string `json:"resourceGroup"`
Kind CosmosDBKind `json:"kind,omitempty"`
Properties CosmosDBProperties `json:"properties,omitempty"`
}

// CosmosDBKind enumerates the values for kind.
// Only one of the following kinds may be specified.
// If none of the following kinds is specified, the default one
// is GlobalDocumentDBKind.
// +kubebuilder:validation:Enum=GlobalDocumentDB;MongoDB
type CosmosDBKind string

const (
CosmosDBKindGlobalDocumentDB CosmosDBKind = "GlobalDocumentDB"
CosmosDBKindMongoDB CosmosDBKind = "MongoDB"
)

// CosmosDBProperties the CosmosDBProperties of CosmosDB.
type CosmosDBProperties struct {
// CosmosDBDatabaseAccountOfferType - The offer type for the Cosmos DB database account.
DatabaseAccountOfferType CosmosDBDatabaseAccountOfferType `json:"databaseAccountOfferType,omitempty"`
//Locations []CosmosDBLocation `json:"locations,omitempty"`
}

// +kubebuilder:validation:Enum=Standard
type CosmosDBDatabaseAccountOfferType string

const (
CosmosDBDatabaseAccountOfferTypeStandard CosmosDBDatabaseAccountOfferType = "Standard"
)

/*
type CosmosDBLocation struct {
FailoverPriority int `json:"failoverPriority,omitempty"`
LocationName string `json:"locationName,omitempty"`
IsZoneRedundant bool `json:"isZoneRedundant,omitempty"`
}
*/

// CosmosDBStatus defines the observed state of CosmosDB
type CosmosDBStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// DeploymentName string `json:"deploymentName,omitempty"`
// ProvisioningState string `json:"provisioningState,omitempty"`
// Generation int64 `json:"generation,omitempty"`
Provisioning bool `json:"provisioning,omitempty"`
Provisioned bool `json:"provisioned,omitempty"`
}

type CosmosDBOutput struct {
CosmosDBName string `json:"cosmosDBName,omitempty"`
PrimaryMasterKey string `json:"primaryMasterKey,omitempty"`
//SecondaryMasterKey string `json:"secondaryMasterKey,omitempty"`
//PrimaryReadonlyMasterKey string `json:"primaryReadonlyMasterKey,omitempty"`
//SecondaryReadonlyMasterKey string `json:"secondaryReadonlyMasterKey,omitempty"`
}

// CosmosDBAdditionalResources holds the additional resources
type CosmosDBAdditionalResources struct {
Secrets []string `json:"secrets,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

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

Spec CosmosDBSpec `json:"spec,omitempty"`
Status CosmosDBStatus `json:"status,omitempty"`
Output CosmosDBOutput `json:"output,omitempty"`
AdditionalResources CosmosDBAdditionalResources `json:"additionalResources,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

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

func init() {
SchemeBuilder.Register(&CosmosDB{}, &CosmosDBList{})
}

func (cosmosDB *CosmosDB) IsSubmitted() bool {
return cosmosDB.Status.Provisioning || cosmosDB.Status.Provisioned
}
131 changes: 131 additions & 0 deletions api/v1/rediscache_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
MIT License
Copyright (c) Microsoft Corporation. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
*/

package v1

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.

// RedisCacheSpec defines the desired state of RedisCache
type RedisCacheSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:validation:MinLength=0

Location string `json:"location,omitempty"`
ResourceGroupName string `json:"resourceGroup"`
Properties RedisCacheProperties `json:"properties,omitempty"`
}

// RedisCacheProperties the properties of the Redis Cache.
type RedisCacheProperties struct {
Sku RedisCacheSku `json:"sku,omitempty"`

EnableNonSslPort bool `json:"enableNonSslPort,omitempty"`
}

// RedisCacheSku the SKU of the Redis Cache.
type RedisCacheSku struct {
// Name - The SKU name. Required for account creation; optional for update.
// Possible values include: 'StandardLRS', 'StandardGRS', 'StandardRAGRS', 'StandardZRS', 'PremiumLRS', 'PremiumZRS', 'StandardGZRS', 'StandardRAGZRS'
Name RedisCacheSkuName `json:"name,omitempty"`

Family RedisCacheSkuFamily `json:"family,omitempty"`

Capacity int32 `json:"capacity,omitempty"`
}

type RedisCacheSkuName string

const (
Basic RedisCacheSkuName = "Basic"
Premium RedisCacheSkuName = "Premium"
Standard RedisCacheSkuName = "Standard"
)

type RedisCacheSkuFamily string

const (
C RedisCacheSkuFamily = "C"
P RedisCacheSkuFamily = "P"
)

// RedisCacheStatus defines the observed state of RedisCache
type RedisCacheStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// DeploymentName string `json:"deploymentName,omitempty"`
// ProvisioningState string `json:"provisioningState,omitempty"`
// Generation int64 `json:"generation,omitempty"`
Provisioning bool `json:"provisioning,omitempty"`
Provisioned bool `json:"provisioned,omitempty"`
}

type RedisCacheOutput struct {
RedisCacheName string `json:"redisCacheName,omitempty"`
PrimaryKey string `json:"primaryKey,omitempty"`
SecondaryKey string `json:"secondaryKey,omitempty"`
}

// StorageAdditionalResources holds the additional resources
type RedisCacheAdditionalResources struct {
Secrets []string `json:"secrets,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

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

Spec RedisCacheSpec `json:"spec,omitempty"`
Status RedisCacheStatus `json:"status,omitempty"`
Output RedisCacheOutput `json:"output,omitempty"`
AdditionalResources RedisCacheAdditionalResources `json:"additionalResources,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&RedisCache{}, &RedisCacheList{})
}

func (redisCache *RedisCache) IsSubmitted() bool {
return redisCache.Status.Provisioning || redisCache.Status.Provisioned
}
Loading

0 comments on commit f676751

Please sign in to comment.