Skip to content

Commit

Permalink
Add GetClusterScopedResources to App interface (#1033)
Browse files Browse the repository at this point in the history
* Add getClusterScopedResources to App interface

* Apply suggestions from code review

Co-authored-by: Prasad Ghangal <prasad.ghangal@gmail.com>

* lint fixed

Co-authored-by: Prasad Ghangal <prasad.ghangal@gmail.com>
  • Loading branch information
akankshakumari393 and PrasadG193 committed Jun 24, 2021
1 parent abf5956 commit f33c70c
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type App interface {
Object() crv1alpha1.ObjectReference
// Uninstall deletes an app and all it's components from a Namespace.
Uninstall(context.Context) error
// GetClusterScopedResources returns the list of cluster scoped k8s resources created during app Install
GetClusterScopedResources(context.Context) []crv1alpha1.ObjectReference
}

// DatabaseApp inherits methods from App, but also includes method to add, read
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func (cas *CassandraInstance) Uninstall(ctx context.Context) error {
return nil
}

func (cas *CassandraInstance) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

// Ping is used to ping the application to check the datbase connectivity
func (cas *CassandraInstance) Ping(ctx context.Context) error {
log.Print("Pinging the application.", field.M{"app": cas.name})
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/couchbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ func (cb CouchbaseDB) Uninstall(ctx context.Context) error {
return errors.Wrapf(err, "Failed to uninstall %s helm release", cb.chart.Release)
}

func (cb CouchbaseDB) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (cb CouchbaseDB) execCommand(ctx context.Context, command []string) (string, string, error) {
// Get pod and container name
podName, err := cb.getRunningCBPod()
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func (esi *ElasticsearchInstance) Uninstall(ctx context.Context) error {
return nil
}

func (esi *ElasticsearchInstance) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (esi *ElasticsearchInstance) Ping(ctx context.Context) error {
log.Print("Pinging the application to check if its accessible.", field.M{"app": esi.name})

Expand Down
4 changes: 4 additions & 0 deletions pkg/app/foundationdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (fdb *FoundationDB) Uninstall(ctx context.Context) error {
return errors.Wrapf(err, "Error uninstalling the operator. Error=%s", out)
}

func (fdb *FoundationDB) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (fdb *FoundationDB) getRunningFDBPod() (string, error) {
// Format of the name of the pods that get generated is
// helmReleaseName-sample-index
Expand Down
125 changes: 125 additions & 0 deletions pkg/app/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,131 @@ func (kc *KafkaCluster) Install(ctx context.Context, namespace string) error {
return nil
}

func (kc *KafkaCluster) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return []crv1alpha1.ObjectReference{
// ClusterRoles
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-kafka-client",
Resource: "clusterroles",
},
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-cluster-operator-global",
Resource: "clusterroles",
},
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-cluster-operator-namespaced",
Resource: "clusterroles",
},
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-entity-operator",
Resource: "clusterroles",
},
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-topic-operator",
Resource: "clusterroles",
},
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-kafka-broker",
Resource: "clusterroles",
},

// ClusterRoleBindings
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-cluster-operator",
Resource: "clusterrolebindings",
},
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-cluster-operator-kafka-broker-delegation",
Resource: "clusterrolebindings",
},
{
APIVersion: "v1",
Group: "rbac.authorization.k8s.io",
Name: "strimzi-cluster-operator-kafka-client-delegation",
Resource: "clusterrolebindings",
},

// CRDs
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkabridges.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkaconnectors.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkaconnects.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkaconnects2is.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkamirrormaker2s.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkamirrormakers.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkarebalances.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkas.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},

{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkatopics.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
{
APIVersion: "v1",
Group: "apiextensions.k8s.io",
Name: "kafkausers.kafka.strimzi.io",
Resource: "customresourcedefinitions",
},
}
}

// Object return the configmap referred in blueprint
func (kc *KafkaCluster) Object() crv1alpha1.ObjectReference {
return crv1alpha1.ObjectReference{
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (m *MariaDB) Uninstall(ctx context.Context) error {
return nil
}

func (m *MariaDB) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (m *MariaDB) Ping(ctx context.Context) error {
log.Print("Pinging the maria database.", field.M{"app": m.name})

Expand Down
4 changes: 4 additions & 0 deletions pkg/app/mongodb-deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (mongo *MongoDBDepConfig) Uninstall(ctx context.Context) error {
return err
}

func (mongo *MongoDBDepConfig) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (mongo *MongoDBDepConfig) Ping(ctx context.Context) error {
log.Print("Pinging the application", field.M{"app": mongo.name})

Expand Down
4 changes: 4 additions & 0 deletions pkg/app/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func (mongo *MongoDB) Uninstall(ctx context.Context) error {
return errors.Wrapf(err, "Error while uninstalling the application.")
}

func (mongo *MongoDB) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (mongo *MongoDB) Ping(ctx context.Context) error {
log.Print("Pinging the application.", field.M{"app": mongo.name})
pingCMD := []string{"sh", "-c", fmt.Sprintf("mongo admin --authenticationDatabase admin -u %s -p $MONGODB_ROOT_PASSWORD --quiet --eval \"rs.secondaryOk(); db\"", mongo.username)}
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/mysql-deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (mdep *MysqlDepConfig) Uninstall(ctx context.Context) error {
return err
}

func (mdep *MysqlDepConfig) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (mdep *MysqlDepConfig) Ping(ctx context.Context) error {
log.Print("Pinging the application", field.M{"app": mdep.name})

Expand Down
4 changes: 4 additions & 0 deletions pkg/app/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (mdb *MysqlDB) Uninstall(ctx context.Context) error {
return nil
}

func (mdb *MysqlDB) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (mdb *MysqlDB) Ping(ctx context.Context) error {
log.Print("Pinging the mysql database.", field.M{"app": mdb.name})

Expand Down
4 changes: 4 additions & 0 deletions pkg/app/postgresql-deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ func (pgres *PostgreSQLDepConfig) Uninstall(ctx context.Context) error {
return err
}

func (pgres *PostgreSQLDepConfig) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (pgres *PostgreSQLDepConfig) Ping(ctx context.Context) error {
cmd := "pg_isready -U 'postgres' -h 127.0.0.1 -p 5432"
_, stderr, err := pgres.execCommand(ctx, []string{"bash", "-c", cmd})
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ func (pdb PostgresDB) Uninstall(ctx context.Context) error {
return errors.Wrapf(cli.Uninstall(ctx, pdb.chart.Release, pdb.namespace), "Failed to uninstall %s helm release", pdb.chart.Release)
}

func (pdp *PostgresDB) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (pdb PostgresDB) execCommand(ctx context.Context, command []string) (string, string, error) {
// Get pod and container name
pod, container, err := kube.GetPodContainerFromStatefulSet(ctx, pdb.cli, pdb.namespace, pdb.getStatefulSetName())
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/rds_aurora_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ func (a *RDSAuroraMySQLDB) Uninstall(ctx context.Context) error {
return nil
}

func (a *RDSAuroraMySQLDB) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (a *RDSAuroraMySQLDB) getAWSConfig(ctx context.Context) (*awssdk.Config, string, error) {
config := make(map[string]string)
config[aws.ConfigRegion] = a.region
Expand Down
4 changes: 4 additions & 0 deletions pkg/app/rds_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ func (pdb RDSPostgresDB) Uninstall(ctx context.Context) error {
return nil
}

func (pdb RDSPostgresDB) GetClusterScopedResources(ctx context.Context) []crv1alpha1.ObjectReference {
return nil
}

func (pdb RDSPostgresDB) getAWSConfig(ctx context.Context) (*awssdk.Config, string, error) {
config := make(map[string]string)
config[aws.ConfigRegion] = pdb.region
Expand Down

0 comments on commit f33c70c

Please sign in to comment.