Skip to content

Commit

Permalink
gm: more code clean after initial refactor done
Browse files Browse the repository at this point in the history
1. remove the feature redundant name in all feature controllers(e.g.
'federatedlearningJob' to 'job'), since it has already own independent
package, no need the feature extra name
2. upstream interface optimizaztion
3. fix empty Kind of all CR in downstream
4. add extra doc string
5. fix code style

Signed-off-by: llhuii <liulinghui@huawei.com>
  • Loading branch information
llhuii committed Aug 2, 2021
1 parent 5c1c167 commit e962aab
Show file tree
Hide file tree
Showing 22 changed files with 372 additions and 353 deletions.
4 changes: 4 additions & 0 deletions cmd/sedna-gm/sedna-gm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ limitations under the License.
package main

import (
"math/rand"
"os"
"time"

"k8s.io/component-base/logs"

"github.com/kubeedge/sedna/cmd/sedna-gm/app"
)

func main() {
rand.Seed(time.Now().UnixNano())

command := app.NewControllerCommand()
logs.InitLogs()
defer logs.FlushLogs()
Expand Down
2 changes: 0 additions & 2 deletions pkg/globalmanager/controllers/dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,5 @@ func New(cc *runtime.ControllerContext) (runtime.FeatureControllerI, error) {
},
})

c.addUpstreamHandler(cc)

return c, nil
}
13 changes: 5 additions & 8 deletions pkg/globalmanager/controllers/dataset/downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,23 @@ func (c *Controller) syncToEdge(eventType watch.EventType, obj interface{}) erro
return nil
}

// Since t.Kind may be empty,
// we need to fix the kind here if missing.
// more details at https://github.com/kubernetes/kubernetes/issues/3030
dataset.Kind = KindName

// Here only propagate to the nodes with non empty name
nodeName := dataset.Spec.NodeName
if len(nodeName) == 0 {
return fmt.Errorf("empty node name")
}

// Since t.Kind may be empty,
// we need to fix the kind here if missing.
// more details at https://github.com/kubernetes/kubernetes/issues/3030
if len(dataset.Kind) == 0 {
dataset.Kind = KindName
}

runtime.InjectSecretAnnotations(c.kubeClient, dataset, dataset.Spec.CredentialName)

return c.sendToEdgeFunc(nodeName, eventType, dataset)
}

func (c *Controller) SetDownstreamSendFunc(f runtime.DownstreamSendFunc) error {
c.sendToEdgeFunc = f

return nil
}
4 changes: 2 additions & 2 deletions pkg/globalmanager/controllers/dataset/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func (c *Controller) updateStatus(name, namespace string, status sednav1.Dataset
})
}

func (c *Controller) addUpstreamHandler(cc *runtime.ControllerContext) error {
return cc.UpstreamController.Add(KindName, c.updateFromEdge)
func (c *Controller) SetUpstreamHandler(addFunc runtime.UpstreamHandlerAddFunc) error {
return addFunc(KindName, c.updateFromEdge)
}
5 changes: 5 additions & 0 deletions pkg/globalmanager/controllers/federatedlearning/downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func (c *Controller) syncToEdge(eventType watch.EventType, obj interface{}) erro
return nil
}

// Since Kind may be empty,
// we need to fix the kind here if missing.
// more details at https://github.com/kubernetes/kubernetes/issues/3030
job.Kind = KindName

// broadcast to all nodes specified in spec
nodeset := make(map[string]bool)
for _, trainingWorker := range job.Spec.TrainingWorkers {
Expand Down
Loading

0 comments on commit e962aab

Please sign in to comment.