-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of application CRD implementation
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
1 parent
ca185cb
commit 0c9bf0d
Showing
30 changed files
with
2,339 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.