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

Threescale 7668 #778

Merged
merged 5 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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: {}
147 changes: 147 additions & 0 deletions apis/capabilities/v1beta1/application_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
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
austincunningham marked this conversation as resolved.
Show resolved Hide resolved
// Important: Run "make" to regenerate code after modifying this file

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

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

//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 {
austincunningham marked this conversation as resolved.
Show resolved Hide resolved
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.ProviderAccountHost != other.ProviderAccountHost {
diff := cmp.Diff(b.ProviderAccountHost, other.ProviderAccountHost)
logger.V(1).Info("ProviderAccountHost 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{})
}
111 changes: 111 additions & 0 deletions apis/capabilities/v1beta1/zz_generated.deepcopy.go

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

44 changes: 44 additions & 0 deletions bundle/manifests/3scale-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ metadata:
"name": "Operated ActiveDoc From URL"
}
},
{
"apiVersion": "capabilities.3scale.net/v1beta1",
"kind": "Application",
"metadata": {
"name": "application-sample"
},
"spec": {
"accountCR": {
"name": "developeraccount-sample"
},
"applicationPlanName": "plan01",
"description": "testing application ",
"name": "testApp",
"productCR": {
"name": "product-sample"
},
"suspend": false
}
},
{
"apiVersion": "capabilities.3scale.net/v1beta1",
"kind": "Backend",
Expand Down Expand Up @@ -249,6 +268,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 +351,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