-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc0348f
commit 7a89661
Showing
5 changed files
with
88 additions
and
4 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
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,28 @@ | ||
package schemaherokubectlcli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/schemahero/schemahero/pkg/installer" | ||
) | ||
|
||
func InstallCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "install", | ||
Short: "install the schemahero operator to the cluster", | ||
Long: `...`, | ||
SilenceErrors: true, | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
viper.BindPFlags(cmd.Flags()) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := installer.InstallOperator(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
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,54 @@ | ||
package installer | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
extensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
extensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
) | ||
|
||
func InstallOperator() error { | ||
cfg, err := config.GetConfig() | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get kubernetes config") | ||
} | ||
|
||
client, err := kubernetes.NewForConfig(cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create new kubernetes client") | ||
} | ||
|
||
extensionsClient, err := extensionsclient.NewForConfig(cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "faield to create extensions client") | ||
} | ||
|
||
if err := createDatabasesCRD(client, extensionsClient); err != nil { | ||
return errors.Wrap(err, "failed to create databases crd") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func createDatabasesCRD(client *kubernetes.Clientset, extensionsClient *extensionsclient.ApiextensionsV1Client) error { | ||
databasesCRD := extensionsv1.CustomResourceDefinition{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "apiextensions.k8s.io/v1beta1", | ||
Kind: "CustomResourceDefinition", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "databases.databases.schemahero.io", | ||
}, | ||
Spec: extensionsv1.CustomResourceDefinitionSpec{ | ||
Group: "databases.schemahero.io", | ||
}, | ||
} | ||
|
||
if _, err := extensionsClient.CustomResourceDefinitions().Create(&databasesCRD); err != nil { | ||
return errors.Wrap(err, "failed to create databases crd") | ||
} | ||
|
||
return nil | ||
} |