Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check pre-requisites on OSSM plugin init #7

Merged
merged 18 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions pkg/kfapp/ossm/k8s_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,50 @@ func (o *OssmInstaller) PatchResourceFromFile(filename string, elems ...configty
}
return nil
}

func (o *OssmInstaller) VerifyCRDInstalled(group string, version string, resource string) error {
dynamicClient, err := dynamic.NewForConfig(o.config)
if err != nil {
log.Error(err, "Failed to initialize dynamic client")
return err
}

crdGVR := schema.GroupVersionResource{
Group: group,
Version: version,
Resource: resource,
}

_, err = dynamicClient.Resource(crdGVR).List(context.Background(), metav1.ListOptions{})
return err
bartoszmajsak marked this conversation as resolved.
Show resolved Hide resolved
}

func (o *OssmInstaller) CheckSMCPStatus(name, namespace string) (string, error) {
dynamicClient, err := dynamic.NewForConfig(o.config)
if err != nil {
log.Info("Failed to initialize dynamic client")
return "", err
}

gvr := schema.GroupVersionResource{
Group: "maistra.io",
Version: "v1",
Resource: "servicemeshcontrolplanes",
}

unstructObj, err := dynamicClient.Resource(gvr).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
log.Info("Failed to find SMCP")
return "", err
}

conditions, found, err := unstructured.NestedSlice(unstructObj.Object, "status", "conditions")
if err != nil || !found {
log.Info("status conditions not found or error in parsing of SMCP")
return "", err
}
lastCondition := conditions[len(conditions)-1].(map[string]interface{})
status := lastCondition["type"].(string)

return status, nil
}
28 changes: 27 additions & 1 deletion pkg/kfapp/ossm/ossm_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ func (o *OssmInstaller) Init(_ kftypesv3.ResourceEnum) error {
return internalError(errors.New(reason))
}

// TODO ensure operators are installed
if err := o.VerifyCRDInstalled("operator.authorino.kuadrant.io", "v1beta1", "authorinos"); err != nil {
log.Info("Failed to find the pre-requisite authorinos CRD, please ensure Authorino operator is installed.")
return internalError(err)
}
if err := o.ensureServiceMeshInstalled(pluginSpec); err != nil {
return internalError(err)
}

if err := o.createResourceTracker(); err != nil {
return internalError(err)
Expand Down Expand Up @@ -233,6 +239,26 @@ func (o *OssmInstaller) MigrateDataScienceProjects() error {
return result.ErrorOrNil()
}

func (o *OssmInstaller) ensureServiceMeshInstalled(pluginSpec *ossmplugin.OssmPluginSpec) error {
if err := o.VerifyCRDInstalled("maistra.io", "v2", "servicemeshcontrolplanes"); err != nil {
log.Info("Failed to find the pre-requisite SMCP CRD, please ensure OSSM operator is installed.")
return internalError(err)
}
smcp := pluginSpec.Mesh.Name
smcpNs := pluginSpec.Mesh.Namespace

status, err := o.CheckSMCPStatus(smcp, smcpNs)
if err != nil {
log.Info("An error occurred while checking SMCP status - ensure the SMCP referenced exists.")
return internalError(err)
}
if status != "Ready" {
log.Info("The referenced SMCP is not ready.", "SMCP name", smcp, "SMCP NS", smcpNs)
return internalError(errors.New("SMCP status is not ready"))
}
return nil
}

func internalError(err error) error {
return &kfapisv3.KfError{
Code: int(kfapisv3.INTERNAL_ERROR),
Expand Down
Loading