-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
113 changed files
with
73,012 additions
and
10 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# Notes | ||
Change generate file, https://book.kubebuilder.io/quick-start.html?highlight=docker#run-it-on-the-cluster | ||
|
||
add prometheus folder and monitor yaml. https://book.kubebuilder.io/reference/metrics | ||
|
||
check rbac folder https://book.kubebuilder.io/reference/metrics-reference | ||
API Server needs a `deployment` config yaml file. | ||
|
Binary file not shown.
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,97 @@ | ||
package endpoints | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Alluxio/k8s-operator/api/v1alpha1" | ||
"github.com/emicklei/go-restful" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type AlluxioClusterEndpoint struct { | ||
client client.Client | ||
} | ||
|
||
func NewAlluxioClusterEndpoint(client client.Client) *AlluxioClusterEndpoint { | ||
return &AlluxioClusterEndpoint{client: client} | ||
} | ||
|
||
func (alluxioClusterEndpoint *AlluxioClusterEndpoint) SetupWithWS(ws *restful.WebService) { | ||
ws.Route(ws.GET("alluxio_cluster").To(alluxioClusterEndpoint.show). | ||
Doc("List of AlluxioClusters"). | ||
Returns(200, "OK", &v1alpha1.AlluxioClusterList{})) | ||
|
||
ws.Route(ws.POST("alluxio_cluster").To(alluxioClusterEndpoint.create). | ||
Doc("Create AlluxioClusters"). | ||
Returns(200, "OK", nil). | ||
Returns(400, "Bad Request", nil)) | ||
|
||
ws.Route(ws.DELETE("alluxio_cluster").To(alluxioClusterEndpoint.delete). | ||
Doc("Delete Current AlluxioClusters"). | ||
Returns(200, "OK", nil). | ||
Returns(400, "Bad Request", nil)) | ||
|
||
ws.Route(ws.PATCH("alluxio_cluster").To(alluxioClusterEndpoint.update). | ||
Doc("Update Current AlluxioClusters"). | ||
Returns(200, "OK", nil). | ||
Returns(400, "Bad Request", nil)) | ||
|
||
} | ||
|
||
func (alluxioClusterEndpoint *AlluxioClusterEndpoint) show(request *restful.Request, response *restful.Response) { | ||
// Get AlluxioClusterList | ||
AlluxioClusterList := new(v1alpha1.AlluxioClusterList) | ||
err := alluxioClusterEndpoint.client.List(request.Request.Context(), AlluxioClusterList, &client.ListOptions{}) | ||
// Unable to get: | ||
if err != nil { | ||
writeError(response, 404, Error{ | ||
Title: "Error", | ||
Details: fmt.Sprintf("Could not retrieve list: %s", err), | ||
}) | ||
return | ||
} | ||
// Write to response: | ||
newAL := AlluxioClusterConverter.AlluxioClusterList(AlluxioClusterList) | ||
if err := response.WriteAsJson(newAL); err != nil { | ||
writeError(response, 404, Error{ | ||
Title: "Error", | ||
Details: "Could not list resources", | ||
}) | ||
} | ||
} | ||
|
||
type Test struct { | ||
Title string `json:"title"` | ||
} | ||
|
||
func (alluxioClusterEndpoint *AlluxioClusterEndpoint) create(request *restful.Request, response *restful.Response) { | ||
test := new(Test) | ||
|
||
err := request.ReadEntity(test) | ||
|
||
if err != nil { | ||
writeError(response, 400, Error{ | ||
Title: "Bad Request", | ||
Details: "Could not read entity", | ||
}) | ||
return | ||
} | ||
|
||
writeError(response, 400, Error{ | ||
Title: "Error", | ||
Details: "To Do, can read entity", | ||
}) | ||
} | ||
|
||
func (alluxioClusterEndpoint *AlluxioClusterEndpoint) update(request *restful.Request, response *restful.Response) { | ||
writeError(response, 400, Error{ | ||
Title: "Error", | ||
Details: "To Do", | ||
}) | ||
} | ||
|
||
func (alluxioClusterEndpoint *AlluxioClusterEndpoint) delete(request *restful.Request, response *restful.Response) { | ||
writeError(response, 400, Error{ | ||
Title: "Error", | ||
Details: "To Do", | ||
}) | ||
} |
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,140 @@ | ||
package endpoints | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Alluxio/k8s-operator/api/v1alpha1" | ||
"github.com/emicklei/go-restful" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type DatasetEndpoint struct { | ||
client client.Client | ||
} | ||
|
||
func NewDataSetEndpoint(client client.Client) *DatasetEndpoint { | ||
return &DatasetEndpoint{client: client} | ||
} | ||
|
||
func (datasetEndpoint *DatasetEndpoint) SetupWithWS(ws *restful.WebService) { | ||
ws.Route(ws.GET("dataset").To(datasetEndpoint.show). | ||
Doc("List of Datasets"). | ||
Returns(200, "OK", DatasetList{})) | ||
|
||
ws.Route(ws.POST("dataset").To(datasetEndpoint.create). | ||
Doc("Create a new Dataset"). | ||
Returns(200, "OK", Dataset{}). | ||
Returns(400, "Bad Request", nil)) | ||
|
||
ws.Route(ws.DELETE("dataset").To(datasetEndpoint.delete). | ||
Doc("Delete Current Dataset"). | ||
Returns(200, "OK", nil). | ||
Returns(400, "Bad Request", nil)) | ||
|
||
// todo add more route | ||
} | ||
|
||
func (datasetEndpoint *DatasetEndpoint) show(request *restful.Request, response *restful.Response) { | ||
datasetList := new(v1alpha1.DatasetList) | ||
err := datasetEndpoint.client.List(request.Request.Context(), datasetList, &client.ListOptions{}) | ||
|
||
if err != nil { | ||
writeError(response, 404, Error{ | ||
Title: "Error", | ||
Details: fmt.Sprintf("Could not retrieve list: %s", err), | ||
}) | ||
} else { | ||
// Convert | ||
newDL := DatasetConverter.DatasetList(datasetList) | ||
// Send | ||
if err := response.WriteAsJson(newDL); err != nil { | ||
writeError(response, 404, Error{ | ||
Title: "Error", | ||
Details: "Could not list resources", | ||
}) | ||
} | ||
} | ||
|
||
} | ||
|
||
func (datasetEndpoint *DatasetEndpoint) create(request *restful.Request, response *restful.Response) { | ||
// Read input | ||
dataset := new(Dataset) | ||
err := request.ReadEntity(dataset) | ||
|
||
if err != nil { | ||
writeError(response, 400, Error{ | ||
Title: "Bad Request", | ||
Details: "Could not read entity", | ||
}) | ||
return | ||
} | ||
|
||
// TODO May need validation func | ||
|
||
datasetObj := &v1alpha1.Dataset{ | ||
ObjectMeta: metav1.ObjectMeta{Name: dataset.Name}, | ||
Spec: v1alpha1.DatasetSpec{ | ||
Dataset: v1alpha1.DatasetConf{ | ||
Path: dataset.Path, | ||
Credentials: dataset.Credentials, | ||
}, | ||
}, | ||
} | ||
|
||
// Deploy the object | ||
err = datasetEndpoint.client.Create(request.Request.Context(), datasetObj, &client.CreateOptions{}) | ||
if err != nil { | ||
writeError(response, 400, Error{ | ||
Title: "Error", | ||
Details: fmt.Sprintf("Could not create object: %s", err), | ||
}) | ||
} else { | ||
// Convert | ||
newDatasetObj := DatasetConverter.DatasetObject(datasetObj) | ||
// Send | ||
if err := response.WriteAsJson(newDatasetObj); err != nil { | ||
writeError(response, 404, Error{ | ||
Title: "Error", | ||
Details: "Could not list resources", | ||
}) | ||
} | ||
} | ||
} | ||
|
||
func (datasetEndpoint *DatasetEndpoint) delete(request *restful.Request, response *restful.Response) { | ||
//writeError(response, 404, Error{ | ||
// Title: "Error", | ||
// Details: "To Do", | ||
//}) | ||
dataset := new(Dataset) | ||
err := request.ReadEntity(dataset) | ||
if err != nil { | ||
writeError(response, 400, Error{ | ||
Title: "Bad Request", | ||
Details: "Could not read entity", | ||
}) | ||
return | ||
} | ||
|
||
// TODO May need validation func | ||
|
||
datasetObj := &v1alpha1.Dataset{ | ||
ObjectMeta: metav1.ObjectMeta{Name: dataset.Name}, | ||
Spec: v1alpha1.DatasetSpec{ | ||
Dataset: v1alpha1.DatasetConf{ | ||
Path: dataset.Path, | ||
Credentials: dataset.Credentials, | ||
}, | ||
}, | ||
} | ||
|
||
// Delete the object | ||
if err = datasetEndpoint.client.Delete(request.Request.Context(), datasetObj, &client.DeleteOptions{}); err != nil { | ||
writeError(response, 400, Error{ | ||
Title: "Error", | ||
Details: fmt.Sprintf("Could not Delete object: %s", err), | ||
}) | ||
} | ||
} |
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,46 @@ | ||
package endpoints | ||
|
||
import ( | ||
"github.com/Alluxio/k8s-operator/api/v1alpha1" | ||
"github.com/emicklei/go-restful" | ||
) | ||
|
||
type Endpoint interface { | ||
SetupWithWS(ws *restful.WebService) | ||
} | ||
|
||
type Source struct { | ||
Type string `json:"type"` | ||
BaseURL string `json:"baseUrl,omitempty"` | ||
AccessKey string `json:"accessKey,omitempty"` | ||
SecretKey string `json:"secretKey,omitempty"` | ||
Region string `json:"region,omitempty"` | ||
PathPrefix string `json:"pathPrefix,omitempty"` | ||
} | ||
|
||
type Error struct { | ||
Title string `json:"title"` | ||
Details string `json:"details"` | ||
} | ||
|
||
// AlluxioCluster Part | ||
type AlluxioCluster struct { | ||
Spec *v1alpha1.AlluxioClusterSpec `json:"spec,omitempty"` | ||
Status *v1alpha1.AlluxioClusterStatus `json:"status,omitempty"` | ||
} | ||
|
||
type AlluxioClusterList struct { | ||
Items []AlluxioCluster `json:"items"` | ||
} | ||
|
||
// Dataset Part | ||
type Dataset struct { | ||
Name string `json:"name"` | ||
Path string `json:"path"` | ||
Credentials map[string]string `json:"credentials,omitempty"` | ||
Status *v1alpha1.DatasetStatus `json:"status,omitempty"` | ||
} | ||
|
||
type DatasetList struct { | ||
Items []Dataset `json:"items"` | ||
} |
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,60 @@ | ||
package endpoints | ||
|
||
import ( | ||
"github.com/Alluxio/k8s-operator/api/v1alpha1" | ||
"github.com/emicklei/go-restful" | ||
kubelog "sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
// writeError is a helper func that write error message to rest response | ||
func writeError(response *restful.Response, httpStatus int, err Error) { | ||
if err := response.WriteHeaderAndJson(httpStatus, err, "application/json"); err != nil { | ||
kubelog.Log.Error(err, "Could not write the error response") | ||
} | ||
} | ||
|
||
// DatasetConverter is used to simplify Dataset CRD to struct in types.go | ||
var AlluxioClusterConverter = &alluxioClusterConverter{} | ||
|
||
type alluxioClusterConverter struct{} | ||
|
||
func (c *alluxioClusterConverter) AlluxioClusterObject(d *v1alpha1.AlluxioCluster) *AlluxioCluster { | ||
return &AlluxioCluster{ | ||
Spec: &d.Spec, | ||
Status: &d.Status, | ||
} | ||
} | ||
|
||
func (c *alluxioClusterConverter) AlluxioClusterList(list *v1alpha1.AlluxioClusterList) *AlluxioClusterList { | ||
items := make([]AlluxioCluster, len(list.Items)) | ||
for i, r := range list.Items { | ||
items[i] = *c.AlluxioClusterObject(&r) | ||
} | ||
return &AlluxioClusterList{ | ||
Items: items, | ||
} | ||
} | ||
|
||
// DatasetConverter is used to simplify Dataset CRD to struct in types.go | ||
var DatasetConverter = &datasetConverter{} | ||
|
||
type datasetConverter struct{} | ||
|
||
func (c *datasetConverter) DatasetObject(d *v1alpha1.Dataset) *Dataset { | ||
return &Dataset{ | ||
Name: d.Name, | ||
Path: d.Spec.Dataset.Path, | ||
Credentials: d.Spec.Dataset.Credentials, | ||
Status: &d.Status, | ||
} | ||
} | ||
|
||
func (c *datasetConverter) DatasetList(list *v1alpha1.DatasetList) *DatasetList { | ||
items := make([]Dataset, len(list.Items)) | ||
for i, r := range list.Items { | ||
items[i] = *c.DatasetObject(&r) | ||
} | ||
return &DatasetList{ | ||
Items: items, | ||
} | ||
} |
Oops, something went wrong.