Skip to content

Commit

Permalink
Start of application CRD implementation
Browse files Browse the repository at this point in the history
Create, Read and Update basics working

Fixing nil pointer and adding suspend/resume functionality

Adding external resources check and changing application status

Addressing comments

Add documentation

remove json unmarshal and check for invalid status

move the account and product get to applicationReconciler

remove generated test-suite file

update to 3scale-porta-go-client v0.7.0

make bundle

add basic unit tests for create and delete application CR

test for suspension/live and change plan ID

update the status on the developer account not found
  • Loading branch information
Patryk-Stefanski authored and austincunningham committed Oct 7, 2022
1 parent ca185cb commit 0c9bf0d
Show file tree
Hide file tree
Showing 30 changed files with 2,339 additions and 9 deletions.
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ resources:
- group: capabilities
kind: ProxyConfigPromote
version: v1beta1
- group: capabilities
kind: Application
version: v1beta1
version: 3-alpha
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
1 change: 0 additions & 1 deletion apis/apps/v1alpha1/zz_generated.deepcopy.go

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

1 change: 0 additions & 1 deletion apis/capabilities/v1alpha1/zz_generated.deepcopy.go

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

141 changes: 141 additions & 0 deletions apis/capabilities/v1beta1/application_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
Copyright 2020 Red Hat.
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 v1beta1

import (
"github.com/3scale/3scale-operator/pkg/common"
"github.com/go-logr/logr"
"github.com/google/go-cmp/cmp"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"reflect"
)

const (
ApplicationReadyConditionType common.ConditionType = "Ready"
)

// 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.

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

//AccountCRName name of account custom resource under which the application will be created
AccountCRName *corev1.LocalObjectReference `json:"accountCRName"`

//ProductCRName of product custom resource from which the application plan will be used
ProductCRName *corev1.LocalObjectReference `json:"productCRName"`

//ApplicationPlanName name of application plan that the application will use
ApplicationPlanName string `json:"applicationPlanName"`

//Name identifies the application uniquely within the account
Name string `json:"name"`

//Description human-readable text of the application
Description string `json:"description"`

//Suspend application if true suspends application, if false resumes application.
//+optional
Suspend bool `json:"suspend,omitempty"`
}

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

// +optional
ID *int64 `json:"applicationID,omitempty"`

// 3scale control plane host
// +optional
ProviderAccountHost string `json:"providerAccountHost,omitempty"`

// +optional
State string `json:"state,omitempty"`

// ObservedGeneration reflects the generation of the most recently observed Application Spec.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// Current state of the 3scale application.
// Conditions represent the latest available observations of an object's state
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions common.Conditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"`
}

func (b *ApplicationStatus) Equals(other *ApplicationStatus, logger logr.Logger) bool {
if !reflect.DeepEqual(b.ID, other.ID) {
diff := cmp.Diff(b.ID, other.ID)
logger.V(1).Info("ID not equal", "difference", diff)
return false
}

if b.State != other.State {
diff := cmp.Diff(b.State, other.State)
logger.V(1).Info("State not equal", "difference", diff)
return false
}

if b.ObservedGeneration != other.ObservedGeneration {
diff := cmp.Diff(b.ObservedGeneration, other.ObservedGeneration)
logger.V(1).Info("ObservedGeneration not equal", "difference", diff)
return false
}

// Marshalling sorts by condition type
currentMarshaledJSON, _ := b.Conditions.MarshalJSON()
otherMarshaledJSON, _ := other.Conditions.MarshalJSON()
if string(currentMarshaledJSON) != string(otherMarshaledJSON) {
diff := cmp.Diff(string(currentMarshaledJSON), string(otherMarshaledJSON))
logger.V(1).Info("Conditions not equal", "difference", diff)
return false
}

return true
}

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

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

Spec ApplicationSpec `json:"spec,omitempty"`
Status ApplicationStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&Application{}, &ApplicationList{})
}
102 changes: 101 additions & 1 deletion apis/capabilities/v1beta1/zz_generated.deepcopy.go

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

40 changes: 40 additions & 0 deletions bundle/manifests/3scale-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ metadata:
"name": "Operated ActiveDoc From URL"
}
},
{
"apiVersion": "capabilities.3scale.net/v1beta1",
"kind": "Application",
"metadata": {
"name": "application-sample"
},
"spec": {
"accountCRName": "developeraccount-sample",
"applicationPlanName": "plan01",
"description": "testing application ",
"name": "testApp",
"productCRName": "product-sample",
"suspend": false
}
},
{
"apiVersion": "capabilities.3scale.net/v1beta1",
"kind": "Backend",
Expand Down Expand Up @@ -249,6 +264,11 @@ spec:
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:podStatuses
version: v1alpha1
- description: Application is the Schema for the applications API
displayName: Application
kind: Application
name: applications.capabilities.3scale.net
version: v1beta1
- description: Backend is the Schema for the backends API
displayName: 3scale Backend
kind: Backend
Expand Down Expand Up @@ -327,6 +347,26 @@ spec:
spec:
clusterPermissions:
- rules:
- apiGroups:
- capabilities.3scale.net
resources:
- applications
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- capabilities.3scale.net
resources:
- applications/status
verbs:
- get
- patch
- update
- apiGroups:
- capabilities.3scale.net
resources:
Expand Down
Loading

0 comments on commit 0c9bf0d

Please sign in to comment.