Skip to content

Commit

Permalink
Merge pull request #3052 from adam-cattermole/MGDAPI-4907
Browse files Browse the repository at this point in the history
MGDAPI-4907 - Add MCG reconciler
  • Loading branch information
openshift-merge-robot authored Jan 24, 2023
2 parents 4ef0fb0 + 5bf5716 commit 654e6ff
Show file tree
Hide file tree
Showing 90 changed files with 8,066 additions and 568 deletions.
5 changes: 4 additions & 1 deletion apis/v1alpha1/addtoscheme_integreatly_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
keycloak "github.com/integr8ly/keycloak-client/apis/keycloak/v1alpha1"

threescalev1 "github.com/3scale/3scale-operator/apis/apps/v1alpha1"

obv1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1"
noobaav1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1"
appsv1 "github.com/openshift/api/apps/v1"
authv1 "github.com/openshift/api/authorization/v1"
confv1 "github.com/openshift/api/config/v1"
Expand Down Expand Up @@ -74,5 +75,7 @@ func init() {
observabilityoperator.SchemeBuilder.AddToScheme,
customdomainv1alpha1.AddToScheme,
cloudcredentialv1.AddToScheme,
noobaav1.SchemeBuilder.AddToScheme,
obv1.SchemeBuilder.AddToScheme,
)
}
3 changes: 3 additions & 0 deletions apis/v1alpha1/rhmi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var (
ProductMonitoringSpec ProductName = "monitoring-spec"
ProductMarin3r ProductName = "marin3r"
ProductGrafana ProductName = "grafana"
ProductMCG ProductName = "mcg"

// Could not find a way to determine these versions dynamically, so they are hard-coded
// It is preferable to determine the version of a product dynamically (from a CR, or configmap, etc)
Expand All @@ -75,6 +76,7 @@ var (
VersionRHSSOUser ProductVersion = "7.6"
VersionMonitoringSpec ProductVersion = "1.0"
VersionMarin3r ProductVersion = "0.11.0"
VersionMCG ProductVersion = "4.11.4"
VersionGrafana ProductVersion = "4.2.0"
VersionObservability ProductVersion = "4.0.0"

Expand All @@ -93,6 +95,7 @@ var (
OperatorVersionMarin3r OperatorVersion = "0.11.0"
OperatorVersionGrafana OperatorVersion = "4.2.0"
OperatorVersionObservability OperatorVersion = "4.0.0"
OperatorVersionMCG OperatorVersion = "4.11.4"

// Event reasons to be used when emitting events
EventProcessingError string = "ProcessingError"
Expand Down
27 changes: 27 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ rules:
- get
- list
- update
- apiGroups:
- noobaa.io
resources:
- backingstores
- bucketclasses
- noobaas
verbs:
- create
- get
- list
- update
- apiGroups:
- oauth.openshift.io
resources:
Expand All @@ -260,6 +271,22 @@ rules:
- delete
- get
- update
- apiGroups:
- objectbucket.io
resources:
- objectbucketclaims
verbs:
- create
- get
- list
- update
- watch
- apiGroups:
- objectbucket.io
resources:
- objectbuckets
verbs:
- list
- apiGroups:
- observability.redhat.com
resources:
Expand Down
6 changes: 5 additions & 1 deletion controllers/rhmi/rhmi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ func New(mgr ctrl.Manager) *RHMIReconciler {

// +kubebuilder:rbac:groups=apps.openshift.io,resources=deploymentconfigs/instantiate,verbs=create

// +kubebuilder:rbac:groups=noobaa.io,resources=noobaas;backingstores;bucketclasses,verbs=get;create;update;list
// +kubebuilder:rbac:groups=objectbucket.io,resources=objectbucketclaims,verbs=get;create;update;list;watch
// +kubebuilder:rbac:groups=objectbucket.io,resources=objectbuckets,verbs=list

func (r *RHMIReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
reconcileDelayedMetric := metrics.InstallationControllerReconcileDelayed
Expand Down Expand Up @@ -318,7 +322,7 @@ func (r *RHMIReconciler) Reconcile(ctx context.Context, request ctrl.Request) (c
}
}

installType, err := TypeFactory(installation.Spec.Type)
installType, err := TypeFactory(ctx, installation.Spec.Type, r.Client)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
32 changes: 28 additions & 4 deletions controllers/rhmi/types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package controllers

import (
"context"
"errors"
"fmt"

integreatlyv1alpha1 "github.com/integr8ly/integreatly-operator/apis/v1alpha1"
"github.com/integr8ly/integreatly-operator/pkg/resources"
configv1 "github.com/openshift/api/config/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type Stage struct {
Expand Down Expand Up @@ -113,8 +118,8 @@ func (t *Type) HasProduct(product string) bool {
return false
}

//GetInstallStages returns indexed arrays of products names this is worked through starting at 0
//the install will not move to the next index until all installs in the current index have completed successfully
// GetInstallStages returns indexed arrays of products names this is worked through starting at 0
// the install will not move to the next index until all installs in the current index have completed successfully
func (t *Type) GetInstallStages() []Stage {
return t.InstallStages
}
Expand All @@ -123,11 +128,30 @@ func (t *Type) GetUninstallStages() []Stage {
return t.UninstallStages
}

func TypeFactory(installationType string) (*Type, error) {
func TypeFactory(ctx context.Context, installationType string, c client.Client) (*Type, error) {
//TODO: export this logic to a configmap for each installation type
switch installationType {
case string(integreatlyv1alpha1.InstallationTypeManagedApi):
return newManagedApiType(), nil
platform, err := resources.GetPlatformType(ctx, c)
if err != nil {
return nil, fmt.Errorf("failed to determine platform type: %v", err)
}
managedApiType := newManagedApiType()
if platform == configv1.GCPPlatformType {
for i := range managedApiType.InstallStages {
if managedApiType.InstallStages[i].Name == integreatlyv1alpha1.InstallStage {
managedApiType.InstallStages[i].Products[integreatlyv1alpha1.ProductMCG] = integreatlyv1alpha1.RHMIProductStatus{Name: integreatlyv1alpha1.ProductMCG}
break
}
}
for i := range managedApiType.UninstallStages {
if managedApiType.UninstallStages[i].Name == integreatlyv1alpha1.UninstallCloudResourcesStage {
managedApiType.UninstallStages[i].Products[integreatlyv1alpha1.ProductMCG] = integreatlyv1alpha1.RHMIProductStatus{Name: integreatlyv1alpha1.ProductMCG}
break
}
}
}
return managedApiType, nil
case string(integreatlyv1alpha1.InstallationTypeMultitenantManagedApi):
return newMultitenantManagedApiType(), nil
default:
Expand Down
151 changes: 151 additions & 0 deletions controllers/rhmi/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package controllers

import (
"context"
"reflect"
"strings"
"testing"

integreatlyv1alpha1 "github.com/integr8ly/integreatly-operator/apis/v1alpha1"
"github.com/integr8ly/integreatly-operator/test/utils"
configv1 "github.com/openshift/api/config/v1"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestReconciler_TypeFactory(t *testing.T) {
scheme, err := utils.NewTestScheme()
if err != nil {
t.Fatal(err)
}
mcgTestStages := &Type{
[]Stage{
{
Name: integreatlyv1alpha1.BootstrapStage,
},
{
Name: integreatlyv1alpha1.InstallStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductCloudResources: {Name: integreatlyv1alpha1.ProductCloudResources},
integreatlyv1alpha1.ProductMCG: {Name: integreatlyv1alpha1.ProductMCG},
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability},
integreatlyv1alpha1.ProductRHSSO: {Name: integreatlyv1alpha1.ProductRHSSO},
integreatlyv1alpha1.Product3Scale: {Name: integreatlyv1alpha1.Product3Scale},
integreatlyv1alpha1.ProductRHSSOUser: {Name: integreatlyv1alpha1.ProductRHSSOUser},
integreatlyv1alpha1.ProductMarin3r: {Name: integreatlyv1alpha1.ProductMarin3r},
integreatlyv1alpha1.ProductGrafana: {Name: integreatlyv1alpha1.ProductGrafana},
},
},
},
[]Stage{
{
Name: integreatlyv1alpha1.UninstallProductsStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductRHSSO: {Name: integreatlyv1alpha1.ProductRHSSO},
integreatlyv1alpha1.Product3Scale: {Name: integreatlyv1alpha1.Product3Scale},
integreatlyv1alpha1.ProductRHSSOUser: {Name: integreatlyv1alpha1.ProductRHSSOUser},
integreatlyv1alpha1.ProductMarin3r: {Name: integreatlyv1alpha1.ProductMarin3r},
integreatlyv1alpha1.ProductGrafana: {Name: integreatlyv1alpha1.ProductGrafana},
},
},
{
Name: integreatlyv1alpha1.UninstallCloudResourcesStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductMCG: {Name: integreatlyv1alpha1.ProductMCG},
integreatlyv1alpha1.ProductCloudResources: {Name: integreatlyv1alpha1.ProductCloudResources},
},
},
{
Name: integreatlyv1alpha1.UninstallObservabilityStage,
Products: map[integreatlyv1alpha1.ProductName]integreatlyv1alpha1.RHMIProductStatus{
integreatlyv1alpha1.ProductObservability: {Name: integreatlyv1alpha1.ProductObservability},
},
},
{
Name: integreatlyv1alpha1.UninstallBootstrap,
},
},
}
type args struct {
installationType integreatlyv1alpha1.InstallationType
client client.Client
}
tests := []struct {
name string
args args
want *Type
err error
}{
{
name: "default managed api return type",
args: args{
client: fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(buildTestInfra(configv1.AWSPlatformType)).Build(),
installationType: integreatlyv1alpha1.InstallationTypeManagedApi,
},
want: newManagedApiType(),
err: nil,
},
{
name: "gcp mcg managed api return type",
args: args{
client: fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(buildTestInfra(configv1.GCPPlatformType)).Build(),
installationType: integreatlyv1alpha1.InstallationTypeManagedApi,
},
want: mcgTestStages,
err: nil,
},
{
name: "default multitenant managed api return type",
args: args{
client: fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(buildTestInfra(configv1.AWSPlatformType)).Build(),
installationType: integreatlyv1alpha1.InstallationTypeMultitenantManagedApi,
},
want: newMultitenantManagedApiType(),
err: nil,
},
{
name: "error retrieving platform type",
args: args{
client: fake.NewClientBuilder().WithScheme(scheme).Build(),
installationType: integreatlyv1alpha1.InstallationTypeManagedApi,
},
want: nil,
err: errors.New("failed to determine platform type:"),
},
{
name: "error unknown installation type",
args: args{
installationType: "unknown-type",
},
want: nil,
err: errors.New("unknown installation type:"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := TypeFactory(context.TODO(), string(tt.args.installationType), tt.args.client)
if err != nil && tt.err != nil && !strings.Contains(err.Error(), tt.err.Error()) {
t.Errorf("TypeFactory() error = %v, err %v", err, tt.err)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("TypeFactory() got = %v, want %v", got, tt.want)
}
})
}
}

func buildTestInfra(platformType configv1.PlatformType) *configv1.Infrastructure {
return &configv1.Infrastructure{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster",
},
Status: configv1.InfrastructureStatus{
PlatformStatus: &configv1.PlatformStatus{
Type: platformType,
},
},
}
}
15 changes: 13 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/headzoo/ut v0.0.0-20181013193318-a13b5a7a02ca // indirect
github.com/integr8ly/cloud-resource-operator v0.42.0
github.com/integr8ly/keycloak-client v0.1.11
github.com/noobaa/noobaa-operator/v5 v5.11.0
github.com/onsi/gomega v1.20.1
github.com/openshift/api v3.9.1-0.20191031084152-11eee842dafd+incompatible
github.com/openshift/cluster-samples-operator v0.0.0-20191113195805-9e879e661d71
Expand Down Expand Up @@ -54,11 +55,12 @@ require (

require (
github.com/foxcpp/go-mockdns v1.0.0
github.com/kube-object-storage/lib-bucket-provisioner v0.0.0-20220105185820-c1da9586e05b
github.com/onsi/ginkgo/v2 v2.1.6
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142
github.com/openshift/custom-domains-operator v0.0.0-20220614181227-281815c251d6
github.com/prometheus/common v0.37.0
k8s.io/metrics v0.20.6
k8s.io/metrics v0.24.0
)

require (
Expand Down Expand Up @@ -90,6 +92,7 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.7 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
Expand Down Expand Up @@ -136,7 +139,7 @@ require (
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/miekg/dns v1.1.31 // indirect
github.com/miekg/dns v1.1.40 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
Expand All @@ -151,6 +154,7 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/openshift/cloud-credential-operator v0.0.0-20211102171825-9d7d082fe277 // indirect
github.com/openshift/custom-resource-status v0.0.0-20190801200128-4c95b3a336cd // indirect
github.com/operator-framework/operator-lib v0.11.0 // indirect
github.com/otiai10/copy v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand All @@ -160,6 +164,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/tidwall/pretty v1.0.1 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
go.opencensus.io v0.23.0 // indirect
Expand Down Expand Up @@ -220,3 +225,9 @@ replace k8s.io/client-go => k8s.io/client-go v0.24.3

// Required until the following jira is resolved - https://issues.redhat.com/browse/MGDAPI-4996
replace github.com/grafana-operator/grafana-operator/v4 => github.com/grafana-operator/grafana-operator/v4 v4.2.0

// Required by mcg-operator until they update support for sched-ops
replace github.com/portworx/sched-ops => github.com/portworx/sched-ops v0.20.4-openstorage-rc3

// tag does not exist but referenced by above package
exclude github.com/kubernetes-incubator/external-storage v0.20.4-openstorage-rc2
Loading

0 comments on commit 654e6ff

Please sign in to comment.