-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SK Ali Arman <[email protected]>
- Loading branch information
1 parent
f71f184
commit 3e5996d
Showing
13 changed files
with
346 additions
and
225 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
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,157 @@ | ||
package pauser | ||
|
||
import ( | ||
"context" | ||
|
||
coreapi "kubedb.dev/apimachinery/apis/archiver/v1alpha1" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
kmapi "kmodules.xyz/client-go/api/v1" | ||
kmc "kmodules.xyz/client-go/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func PauseOrResumeMySQLArchiver(klient client.Client, value bool, reference kmapi.ObjectReference) error { | ||
name := reference.Name | ||
namespace := reference.Namespace | ||
archiver, err := getMysqlArchiver(klient, kmapi.ObjectReference{ | ||
Name: name, | ||
Namespace: namespace, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = kmc.CreateOrPatch( | ||
context.Background(), | ||
klient, | ||
archiver, | ||
func(obj client.Object, createOp bool) client.Object { | ||
in := obj.(*coreapi.MySQLArchiver) | ||
in.Spec.Pause = value | ||
return in | ||
}, | ||
) | ||
return err | ||
} | ||
|
||
func getMysqlArchiver(klient client.Client, ref kmapi.ObjectReference) (*coreapi.MySQLArchiver, error) { | ||
archiver := &coreapi.MySQLArchiver{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: ref.Name, | ||
Namespace: ref.Namespace, | ||
}, | ||
} | ||
if err := klient.Get(context.Background(), client.ObjectKeyFromObject(archiver), archiver); err != nil { | ||
return nil, err | ||
} | ||
return archiver, nil | ||
} | ||
|
||
func PauseOrResumeMariaDBArchiver(klient client.Client, value bool, reference kmapi.ObjectReference) error { | ||
name := reference.Name | ||
namespace := reference.Namespace | ||
archiver, err := getMariaDBArchiver(klient, kmapi.ObjectReference{ | ||
Name: name, | ||
Namespace: namespace, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = kmc.CreateOrPatch( | ||
context.Background(), | ||
klient, | ||
archiver, | ||
func(obj client.Object, createOp bool) client.Object { | ||
in := obj.(*coreapi.MariaDBArchiver) | ||
in.Spec.Pause = value | ||
return in | ||
}, | ||
) | ||
return err | ||
} | ||
|
||
func getMariaDBArchiver(klient client.Client, ref kmapi.ObjectReference) (*coreapi.MariaDBArchiver, error) { | ||
archiver := &coreapi.MariaDBArchiver{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: ref.Name, | ||
Namespace: ref.Namespace, | ||
}, | ||
} | ||
if err := klient.Get(context.Background(), client.ObjectKeyFromObject(archiver), archiver); err != nil { | ||
return nil, err | ||
} | ||
|
||
return archiver, nil | ||
} | ||
|
||
func PauseOrResumePostgresArchiver(klient client.Client, value bool, reference kmapi.ObjectReference) error { | ||
name := reference.Name | ||
namespace := reference.Namespace | ||
archiver, err := getPostgresArchiver(klient, kmapi.ObjectReference{ | ||
Name: name, | ||
Namespace: namespace, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = kmc.CreateOrPatch( | ||
context.Background(), | ||
klient, | ||
archiver, | ||
func(obj client.Object, createOp bool) client.Object { | ||
in := obj.(*coreapi.PostgresArchiver) | ||
in.Spec.Pause = value | ||
return in | ||
}, | ||
) | ||
return err | ||
} | ||
|
||
func getPostgresArchiver(klient client.Client, ref kmapi.ObjectReference) (*coreapi.PostgresArchiver, error) { | ||
archiver := &coreapi.PostgresArchiver{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: ref.Name, | ||
Namespace: ref.Namespace, | ||
}, | ||
} | ||
if err := klient.Get(context.Background(), client.ObjectKeyFromObject(archiver), archiver); err != nil { | ||
return nil, err | ||
} | ||
return archiver, nil | ||
} | ||
|
||
func PauseOrResumeMongoDBArchiver(klient client.Client, value bool, reference kmapi.ObjectReference) error { | ||
name := reference.Name | ||
namespace := reference.Namespace | ||
archiver, err := getMongoDBArchiver(klient, kmapi.ObjectReference{ | ||
Name: name, | ||
Namespace: namespace, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = kmc.CreateOrPatch( | ||
context.Background(), | ||
klient, | ||
archiver, | ||
func(obj client.Object, createOp bool) client.Object { | ||
in := obj.(*coreapi.MongoDBArchiver) | ||
in.Spec.Pause = value | ||
return in | ||
}, | ||
) | ||
return err | ||
} | ||
|
||
func getMongoDBArchiver(klient client.Client, ref kmapi.ObjectReference) (*coreapi.MongoDBArchiver, error) { | ||
archiver := &coreapi.MongoDBArchiver{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: ref.Name, | ||
Namespace: ref.Namespace, | ||
}, | ||
} | ||
if err := klient.Get(context.Background(), client.ObjectKeyFromObject(archiver), archiver); err != nil { | ||
return nil, err | ||
} | ||
return archiver, nil | ||
} |
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
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
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
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.