aboutsummaryrefslogtreecommitdiffstats
path: root/src/ovnaction
diff options
context:
space:
mode:
authorEric Multanen <eric.w.multanen@intel.com>2020-04-23 12:55:38 -0700
committerEric Multanen <eric.w.multanen@intel.com>2020-06-03 17:17:21 -0700
commite80f462ab1621090dd9cf7a2c648eb168aaafa5e (patch)
treea94b336dcb30929756077e80dd8ed581b1455088 /src/ovnaction
parent8e7a20777f2100324526a34b4b6c943b512df0fb (diff)
Add grpc contextupdate client call to orchestrator
Adds a contextupdate client function that can be invoked for any action or placement controller to process intents for that controller. Adds the corresponding server side handling for the ovnaction controller. Issue-ID: MULTICLOUD-1019 Signed-off-by: Eric Multanen <eric.w.multanen@intel.com> Change-Id: Ifdfc99e522288a530735bc4c1402d45449f6d057
Diffstat (limited to 'src/ovnaction')
-rw-r--r--src/ovnaction/cmd/main.go6
-rw-r--r--src/ovnaction/go.mod1
-rw-r--r--src/ovnaction/go.sum18
-rw-r--r--src/ovnaction/internal/action/action.go158
-rw-r--r--src/ovnaction/pkg/grpc/contextupdateserver/contextupdateserver.go21
5 files changed, 192 insertions, 12 deletions
diff --git a/src/ovnaction/cmd/main.go b/src/ovnaction/cmd/main.go
index 1f33af25..9e791cd1 100644
--- a/src/ovnaction/cmd/main.go
+++ b/src/ovnaction/cmd/main.go
@@ -26,7 +26,6 @@ import (
"time"
"github.com/gorilla/handlers"
- "github.com/onap/multicloud-k8s/src/ncm/pkg/grpc/contextupdateserver"
updatepb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/contextupdate"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/auth"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config"
@@ -34,6 +33,7 @@ import (
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
"github.com/onap/multicloud-k8s/src/ovnaction/api"
register "github.com/onap/multicloud-k8s/src/ovnaction/pkg/grpc"
+ "github.com/onap/multicloud-k8s/src/ovnaction/pkg/grpc/contextupdateserver"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/testdata"
@@ -73,10 +73,10 @@ func startGrpcServer() error {
grpcServer := grpc.NewServer(opts...)
updatepb.RegisterContextupdateServer(grpcServer, contextupdateserver.NewContextupdateServer())
- log.Println("Starting Network Configuration Manager gRPC Server")
+ log.Println("Starting OVN Network Action Controller gRPC Server")
err = grpcServer.Serve(lis)
if err != nil {
- log.Fatalf("ncm grpc server is not serving %v", err)
+ log.Fatalf("ovnaction grpc server is not serving %v", err)
}
return err
}
diff --git a/src/ovnaction/go.mod b/src/ovnaction/go.mod
index 1050fe83..06b4d581 100644
--- a/src/ovnaction/go.mod
+++ b/src/ovnaction/go.mod
@@ -5,7 +5,6 @@ require (
github.com/gorilla/handlers v1.3.0
github.com/gorilla/mux v1.7.3
github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20200127152046-0ee521d56061
- github.com/onap/multicloud-k8s/src/ncm v0.0.0-20200515060444-c77850a75eee
github.com/onap/multicloud-k8s/src/orchestrator v0.0.0-20200601021239-7959bd4c6fd4
github.com/pkg/errors v0.8.1
google.golang.org/grpc v1.27.1
diff --git a/src/ovnaction/go.sum b/src/ovnaction/go.sum
index ee1c7287..0f8e80de 100644
--- a/src/ovnaction/go.sum
+++ b/src/ovnaction/go.sum
@@ -203,6 +203,13 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
+github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
+github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
+github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
+github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
+github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@@ -787,6 +794,8 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2El
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200305110556-506484158171 h1:xes2Q2k+d/+YNXVw0FpZkIDJiaux4OVrRKXRAzH6A0U=
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
+google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
+google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
@@ -800,6 +809,15 @@ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
+google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
+google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
+google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
+google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA=
+google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
diff --git a/src/ovnaction/internal/action/action.go b/src/ovnaction/internal/action/action.go
new file mode 100644
index 00000000..c9b912fa
--- /dev/null
+++ b/src/ovnaction/internal/action/action.go
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2020 Intel Corporation, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package action
+
+import (
+ "encoding/json"
+ "strings"
+
+ jyaml "github.com/ghodss/yaml"
+
+ nettypes "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
+ log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+ "github.com/onap/multicloud-k8s/src/ovnaction/pkg/module"
+ "k8s.io/apimachinery/pkg/runtime"
+ "k8s.io/client-go/kubernetes/scheme"
+
+ pkgerrors "github.com/pkg/errors"
+)
+
+// Action applies the supplied intent against the given AppContext ID
+func UpdateAppContext(intentName, appContextId string) error {
+ var ac appcontext.AppContext
+ _, err := ac.LoadAppContext(appContextId)
+ if err != nil {
+ return pkgerrors.Wrapf(err, "Error getting AppContext with Id: %v", appContextId)
+ }
+ caMeta, err := ac.GetCompositeAppMeta()
+ if err != nil {
+ return pkgerrors.Wrapf(err, "Error getting metadata for AppContext with Id: %v", appContextId)
+ }
+
+ project := caMeta.Project
+ compositeapp := caMeta.CompositeApp
+ compositeappversion := caMeta.Version
+
+ // Handle all Workload Intents for the Network Control Intent
+ wis, err := module.NewWorkloadIntentClient().GetWorkloadIntents(project, compositeapp, compositeappversion, intentName)
+ if err != nil {
+ return pkgerrors.Wrapf(err, "Error getting Workload Intents for Network Control Intent %v for %v/%v%v not found", intentName, project, compositeapp, compositeappversion)
+ }
+
+ // Handle all intents (currently just Workload Interface intents) for each Workload Intent
+ for _, wi := range wis {
+ // The app/resource identified in the workload intent needs to be updated with two annotations.
+ // 1 - The "k8s.v1.cni.cncf.io/networks" annotation will have {"name": "ovn-networkobj", "namespace": "default"} added
+ // to it (preserving any existing values for this annotation.
+ // 2 - The "k8s.plugin.opnfv.org/nfn-network" annotation will add any network interfaces that are provided by the
+ // workload/interfaces intents.
+
+ // Prepare the list of interfaces from the workload intent
+ wifs, err := module.NewWorkloadIfIntentClient().GetWorkloadIfIntents(project,
+ compositeapp,
+ compositeappversion,
+ intentName,
+ wi.Metadata.Name)
+ if err != nil {
+ return pkgerrors.Wrapf(err,
+ "Error getting Workload Interface Intents for Workload Intent %v under Network Control Intent %v for %v/%v%v not found",
+ wi.Metadata.Name, intentName, project, compositeapp, compositeappversion)
+ }
+ if len(wifs) == 0 {
+ log.Warn("No interface intents provided for workload intent", log.Fields{
+ "project": project,
+ "composite app": compositeapp,
+ "composite app version": compositeappversion,
+ "network control intent": intentName,
+ "workload intent": wi.Metadata.Name,
+ })
+ continue
+ }
+
+ // Get all clusters for the current App from the AppContext
+ clusters, err := ac.GetClusterNames(wi.Spec.AppName)
+ for _, c := range clusters {
+ rh, err := ac.GetResourceHandle(wi.Spec.AppName, c,
+ strings.Join([]string{wi.Spec.WorkloadResource, wi.Spec.Type}, "+"))
+ if err != nil {
+ log.Warn("App Context resource handle not found", log.Fields{
+ "project": project,
+ "composite app": compositeapp,
+ "composite app version": compositeappversion,
+ "network control intent": intentName,
+ "workload name": wi.Metadata.Name,
+ "app": wi.Spec.AppName,
+ "resource": wi.Spec.WorkloadResource,
+ "resource type": wi.Spec.Type,
+ })
+ continue
+ }
+ r, err := ac.GetValue(rh)
+ if err != nil {
+ log.Error("Error retrieving resource from App Context", log.Fields{
+ "error": err,
+ "resource handle": rh,
+ })
+ }
+
+ // Unmarshal resource to K8S object
+ robj, err := runtime.Decode(scheme.Codecs.UniversalDeserializer(), []byte(r.(string)))
+
+ // Add network annotation to object
+ netAnnot := nettypes.NetworkSelectionElement{
+ Name: "ovn-networkobj",
+ Namespace: "default",
+ }
+ module.AddNetworkAnnotation(robj, netAnnot)
+
+ // Add nfn interface annotations to object
+ var newNfnIfs []module.WorkloadIfIntentSpec
+ for _, i := range wifs {
+ newNfnIfs = append(newNfnIfs, i.Spec)
+ }
+ module.AddNfnAnnotation(robj, newNfnIfs)
+
+ // Marshal object back to yaml format (via json - seems to eliminate most clutter)
+ j, err := json.Marshal(robj)
+ if err != nil {
+ log.Error("Error marshalling resource to JSON", log.Fields{
+ "error": err,
+ })
+ continue
+ }
+ y, err := jyaml.JSONToYAML(j)
+ if err != nil {
+ log.Error("Error marshalling resource to YAML", log.Fields{
+ "error": err,
+ })
+ continue
+ }
+
+ // Update resource in AppContext
+ err = ac.UpdateResourceValue(rh, string(y))
+ if err != nil {
+ log.Error("Network updating app context resource handle", log.Fields{
+ "error": err,
+ "resource handle": rh,
+ })
+ }
+ }
+ }
+
+ return nil
+}
diff --git a/src/ovnaction/pkg/grpc/contextupdateserver/contextupdateserver.go b/src/ovnaction/pkg/grpc/contextupdateserver/contextupdateserver.go
index fc548ccc..d0ab95f6 100644
--- a/src/ovnaction/pkg/grpc/contextupdateserver/contextupdateserver.go
+++ b/src/ovnaction/pkg/grpc/contextupdateserver/contextupdateserver.go
@@ -15,10 +15,11 @@ package contextupdateserver
import (
"context"
- "encoding/json"
- "log"
+ "fmt"
contextpb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/grpc/contextupdate"
+ log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+ "github.com/onap/multicloud-k8s/src/ovnaction/internal/action"
//"google.golang.org/grpc/codes"
//"google.golang.org/grpc/status"
)
@@ -28,14 +29,18 @@ type contextupdateServer struct {
}
func (cs *contextupdateServer) UpdateAppContext(ctx context.Context, req *contextpb.ContextUpdateRequest) (*contextpb.ContextUpdateResponse, error) {
- contextUpdateReq, _ := json.Marshal(req)
- log.Println("GRPC Server received contextupdateRequest: ", string(contextUpdateReq))
+ log.Info("Received Update App Context request", log.Fields{
+ "AppContextId": req.AppContext,
+ "IntentName": req.IntentName,
+ })
- // Insert call to Server Functionality here
- //
- //
+ err := action.UpdateAppContext(req.IntentName, req.AppContext)
- return &contextpb.ContextUpdateResponse{AppContextUpdated: true}, nil
+ if err != nil {
+ return &contextpb.ContextUpdateResponse{AppContextUpdated: false, AppContextUpdateMessage: err.Error()}, nil
+ }
+
+ return &contextpb.ContextUpdateResponse{AppContextUpdated: true, AppContextUpdateMessage: fmt.Sprintf("Successful application of intent %v to %v", req.IntentName, req.AppContext)}, nil
}
// NewContextUpdateServer exported