Skip to content

Commit

Permalink
Merge pull request #929 from 3scale/threescale-10163
Browse files Browse the repository at this point in the history
THREESCALE-10163 Migrate from DeploymentConfigs to Deployments
  • Loading branch information
carlkyrillos authored Mar 1, 2024
2 parents 78ecd0e + 86f4b3a commit 61b65b5
Show file tree
Hide file tree
Showing 105 changed files with 3,425 additions and 3,675 deletions.
14 changes: 2 additions & 12 deletions apis/apps/v1alpha1/apimanager_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const (

const (
defaultTenantName = "3scale"
defaultImageStreamImportInsecure = false
defaultResourceRequirementsEnabled = true
)

Expand Down Expand Up @@ -98,7 +97,7 @@ type APIManagerStatus struct {
// +patchStrategy=merge
Conditions common.Conditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"`

// APIManager Deployment Configs
// APIManager Deployments
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Deployments",xDescriptors="urn:alm:descriptor:com.tectonic.ui:podStatuses"
Deployments olm.DeploymentStatus `json:"deployments"`
}
Expand Down Expand Up @@ -130,11 +129,10 @@ func (s *APIManagerStatus) Equals(other *APIManagerStatus, logger logr.Logger) b
// APIManager is the Schema for the apimanagers API
// +kubebuilder:resource:path=apimanagers,scope=Namespaced
// +operator-sdk:csv:customresourcedefinitions:displayName="APIManager"
// +operator-sdk:csv:customresourcedefinitions:resources={{"DeploymentConfig","apps.openshift.io/v1"}}
// +operator-sdk:csv:customresourcedefinitions:resources={{"Deployment","apps/v1"}}
// +operator-sdk:csv:customresourcedefinitions:resources={{"PersistentVolumeClaim","v1"}}
// +operator-sdk:csv:customresourcedefinitions:resources={{"Service","v1"}}
// +operator-sdk:csv:customresourcedefinitions:resources={{"Route","route.openshift.io/v1"}}
// +operator-sdk:csv:customresourcedefinitions:resources={{"ImageStream","image.openshift.io/v1"}}
type APIManager struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -161,8 +159,6 @@ type APIManagerCommonSpec struct {
// +optional
TenantName *string `json:"tenantName,omitempty"`
// +optional
ImageStreamTagImportInsecure *bool `json:"imageStreamTagImportInsecure,omitempty"`
// +optional
ResourceRequirementsEnabled *bool `json:"resourceRequirementsEnabled,omitempty"`
// +optional
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Expand Down Expand Up @@ -977,7 +973,6 @@ func (apimanager *APIManager) setAPIManagerCommonSpecDefaults() bool {

tmpDefaultAppLabel := Default3scaleAppLabel
tmpDefaultTenantName := defaultTenantName
tmpDefaultImageStreamTagImportInsecure := defaultImageStreamImportInsecure
tmpDefaultResourceRequirementsEnabled := defaultResourceRequirementsEnabled

if spec.AppLabel == nil {
Expand All @@ -990,11 +985,6 @@ func (apimanager *APIManager) setAPIManagerCommonSpecDefaults() bool {
changed = true
}

if spec.ImageStreamTagImportInsecure == nil {
spec.ImageStreamTagImportInsecure = &tmpDefaultImageStreamTagImportInsecure
changed = true
}

if spec.ResourceRequirementsEnabled == nil {
spec.ResourceRequirementsEnabled = &tmpDefaultResourceRequirementsEnabled
changed = true
Expand Down
10 changes: 4 additions & 6 deletions apis/apps/v1alpha1/apimanager_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
func TestSetDefaults(t *testing.T) {
tmpDefaultAppLabel := Default3scaleAppLabel
tmpDefaultTenantName := defaultTenantName
tmpDefaultImageStreamTagImportInsecure := defaultImageStreamImportInsecure
tmpDefaultResourceRequirementsEnabled := defaultResourceRequirementsEnabled
tmpDefaultApicastManagementAPI := defaultApicastManagementAPI
tmpDefaultApicastOpenSSLVerify := defaultApicastOpenSSLVerify
Expand All @@ -32,11 +31,10 @@ func TestSetDefaults(t *testing.T) {
},
Spec: APIManagerSpec{
APIManagerCommonSpec: APIManagerCommonSpec{
WildcardDomain: "test.3scale.com",
AppLabel: &tmpDefaultAppLabel,
TenantName: &tmpDefaultTenantName,
ImageStreamTagImportInsecure: &tmpDefaultImageStreamTagImportInsecure,
ResourceRequirementsEnabled: &tmpDefaultResourceRequirementsEnabled,
WildcardDomain: "test.3scale.com",
AppLabel: &tmpDefaultAppLabel,
TenantName: &tmpDefaultTenantName,
ResourceRequirementsEnabled: &tmpDefaultResourceRequirementsEnabled,
},
Apicast: &ApicastSpec{
IncludeResponseCodes: &tmpDefaultApicastResponseCodes,
Expand Down
5 changes: 0 additions & 5 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

9 changes: 3 additions & 6 deletions bundle/manifests/3scale-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,9 @@ spec:
kind: APIManager
name: apimanagers.apps.3scale.net
resources:
- kind: DeploymentConfig
- kind: Deployment
name: ""
version: apps.openshift.io/v1
- kind: ImageStream
name: ""
version: image.openshift.io/v1
version: apps/v1
- kind: PersistentVolumeClaim
name: ""
version: v1
Expand All @@ -264,7 +261,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:label
statusDescriptors:
- description: APIManager Deployment Configs
- description: APIManager Deployments
displayName: Deployments
path: deployments
x-descriptors:
Expand Down
4 changes: 1 addition & 3 deletions bundle/manifests/apps.3scale.net_apimanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3860,8 +3860,6 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
imageStreamTagImportInsecure:
type: boolean
monitoring:
properties:
enablePrometheusRules:
Expand Down Expand Up @@ -10540,7 +10538,7 @@ spec:
type: object
type: array
deployments:
description: APIManager Deployment Configs
description: APIManager Deployments
properties:
ready:
description: Deployments are ready to serve requests
Expand Down
4 changes: 1 addition & 3 deletions config/crd/bases/apps.3scale.net_apimanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7190,8 +7190,6 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
imageStreamTagImportInsecure:
type: boolean
monitoring:
properties:
enablePrometheusRules:
Expand Down Expand Up @@ -19931,7 +19929,7 @@ spec:
type: object
type: array
deployments:
description: APIManager Deployment Configs
description: APIManager Deployments
properties:
ready:
description: Deployments are ready to serve requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ spec:
kind: APIManager
name: apimanagers.apps.3scale.net
resources:
- kind: DeploymentConfig
- kind: Deployment
name: ""
version: apps.openshift.io/v1
- kind: ImageStream
name: ""
version: image.openshift.io/v1
version: apps/v1
- kind: PersistentVolumeClaim
name: ""
version: v1
Expand All @@ -78,7 +75,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:label
statusDescriptors:
- description: APIManager Deployment Configs
- description: APIManager Deployments
displayName: Deployments
path: deployments
x-descriptors:
Expand Down
12 changes: 6 additions & 6 deletions controllers/apps/apimanager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package controllers
import (
"context"
"fmt"
"github.com/3scale/3scale-operator/pkg/upgrade"

appsv1 "github.com/openshift/api/apps/v1"
routev1 "github.com/openshift/api/route/v1"

k8sappsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
apimachinerymetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -40,7 +40,6 @@ import (
"github.com/3scale/3scale-operator/pkg/3scale/amp/operator"
"github.com/3scale/3scale-operator/pkg/3scale/amp/product"
"github.com/3scale/3scale-operator/pkg/handlers"

"github.com/3scale/3scale-operator/pkg/helper"
"github.com/3scale/3scale-operator/pkg/reconcilers"
"github.com/3scale/3scale-operator/version"
Expand Down Expand Up @@ -154,7 +153,7 @@ func (r *APIManagerReconciler) SetupWithManager(mgr ctrl.Manager) error {
handler.EnqueueRequestsFromMapFunc(secretToApimanagerEventMapper.Map),
builder.WithPredicates(labelSelectorPredicate),
).
Owns(&appsv1.DeploymentConfig{}).
Owns(&k8sappsv1.Deployment{}).
Watches(&source.Kind{Type: &routev1.Route{}}, handler.EnqueueRequestsFromMapFunc(handlers.Map)).
Complete(r)
}
Expand Down Expand Up @@ -262,6 +261,9 @@ func (r *APIManagerReconciler) reconcileAPIManagerLogic(cr *appsv1alpha1.APIMana
return result, err
}

// 3scale 2.14 -> 2.15
err = upgrade.DeleteImageStreams(r.WatchedNamespace, r.Client())

return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -337,12 +339,10 @@ func (r *APIManagerReconciler) dependencyReconcilerForComponents(cr *appsv1alpha
if cr.Spec.System.DatabaseSpec != nil && cr.Spec.System.DatabaseSpec.PostgreSQL != nil {
systemDatabaseReconcilerConstructor = operator.CompositeDependencyReconcilerConstructor(
operator.NewSystemPostgreSQLReconciler,
operator.NewSystemPostgreSQLImageReconciler,
)
} else {
systemDatabaseReconcilerConstructor = operator.CompositeDependencyReconcilerConstructor(
operator.NewSystemMySQLReconciler,
operator.NewSystemMySQLImageReconciler,
)
}

Expand Down
24 changes: 12 additions & 12 deletions controllers/apps/apimanager_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/google/uuid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
appsv1 "github.com/openshift/api/apps/v1"
routev1 "github.com/openshift/api/route/v1"
k8sappsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -143,10 +143,10 @@ var _ = Describe("APIManager controller", func() {
return err == nil
}, 5*time.Minute, 5*time.Second).Should(BeTrue())

fmt.Fprintf(GinkgoWriter, "Waiting for all APIManager managed DeploymentConfigs\n")
err = waitForAllAPIManagerStandardDeploymentConfigs(testNamespace, 5*time.Second, 15*time.Minute, GinkgoWriter)
fmt.Fprintf(GinkgoWriter, "Waiting for all APIManager managed Deployments\n")
err = waitForAllAPIManagerStandardDeployments(testNamespace, 5*time.Second, 15*time.Minute, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
fmt.Fprintf(GinkgoWriter, "All APIManager managed DeploymentConfigs are ready\n")
fmt.Fprintf(GinkgoWriter, "All APIManager managed Deployments are ready\n")

fmt.Fprintf(GinkgoWriter, "Waiting for all APIManager managed Routes\n")
err = waitForAllAPIManagerStandardRoutes(testNamespace, 5*time.Second, 15*time.Minute, wildcardDomain, GinkgoWriter)
Expand All @@ -164,8 +164,8 @@ var _ = Describe("APIManager controller", func() {
})
})

func waitForAllAPIManagerStandardDeploymentConfigs(namespace string, retryInterval, timeout time.Duration, w io.Writer) error {
deploymentConfigNames := []string{ // TODO gather this from constants/somewhere centralized
func waitForAllAPIManagerStandardDeployments(namespace string, retryInterval, timeout time.Duration, w io.Writer) error {
deploymentNames := []string{ // TODO gather this from constants/somewhere centralized
"apicast-production",
"apicast-staging",
"backend-cron",
Expand All @@ -183,23 +183,23 @@ func waitForAllAPIManagerStandardDeploymentConfigs(namespace string, retryInterv
"zync-database",
}

for _, dcName := range deploymentConfigNames {
lookupKey := types.NamespacedName{Name: dcName, Namespace: namespace}
createdDeployment := &appsv1.DeploymentConfig{}
for _, dName := range deploymentNames {
lookupKey := types.NamespacedName{Name: dName, Namespace: namespace}
createdDeployment := &k8sappsv1.Deployment{}
Eventually(func() bool {
err := testK8sClient.Get(context.Background(), lookupKey, createdDeployment)
if err != nil {
return false
}

if helper.IsDeploymentConfigAvailable(createdDeployment) {
fmt.Fprintf(w, "DeploymentConfig '%s' available\n", dcName)
if helper.IsDeploymentAvailable(createdDeployment) {
fmt.Fprintf(w, "Deployment '%s' available\n", dName)
return true
}

availableReplicas := createdDeployment.Status.AvailableReplicas
desiredReplicas := createdDeployment.Spec.Replicas
fmt.Fprintf(w, "Waiting for full availability of %s DeploymentConfig (%d/%d)\n", dcName, availableReplicas, desiredReplicas)
fmt.Fprintf(w, "Waiting for full availability of %s Deployment (%d/%d)\n", dName, availableReplicas, desiredReplicas)
return false

}, timeout, retryInterval).Should(BeTrue())
Expand Down
Loading

0 comments on commit 61b65b5

Please sign in to comment.