Dynamic Runtime source for k8s with github packages (#1252)
* Dynamic Runtime source for k8s * Still check for source * Replace / with - for k8s service names * Simplify sourceForName function
This commit is contained in:
@@ -270,9 +270,9 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er
|
||||
if len(options.Type) == 0 {
|
||||
options.Type = k.options.Type
|
||||
}
|
||||
if len(k.options.Source) > 0 {
|
||||
s.Source = k.options.Source
|
||||
}
|
||||
|
||||
// determine the full source for this service
|
||||
options.Source = k.sourceForService(s.Name)
|
||||
|
||||
service := newService(s, options)
|
||||
|
||||
@@ -329,7 +329,8 @@ func (k *kubernetes) List() ([]*runtime.Service, error) {
|
||||
func (k *kubernetes) Update(s *runtime.Service) error {
|
||||
// create new kubernetes micro service
|
||||
service := newService(s, runtime.CreateOptions{
|
||||
Type: k.options.Type,
|
||||
Type: k.options.Type,
|
||||
Source: k.sourceForService(s.Name),
|
||||
})
|
||||
|
||||
// update build time annotation
|
||||
@@ -432,3 +433,15 @@ func NewRuntime(opts ...runtime.Option) runtime.Runtime {
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
// sourceForService determines the nested package name for github
|
||||
// e.g src: docker.pkg.github.com/micro/services an srv: users/api
|
||||
// would become docker.pkg.github.com/micro/services/users-api
|
||||
func (k *kubernetes) sourceForService(name string) string {
|
||||
if !strings.HasPrefix(k.options.Source, "docker.pkg.github.com") {
|
||||
return k.options.Source
|
||||
}
|
||||
|
||||
formattedName := strings.ReplaceAll(name, "/", "-")
|
||||
return fmt.Sprintf("%v/%v", k.options.Source, formattedName)
|
||||
}
|
||||
|
@@ -34,9 +34,9 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service {
|
||||
kservice := client.NewService(name, version, c.Type)
|
||||
kdeploy := client.NewDeployment(name, version, c.Type)
|
||||
|
||||
if len(s.Source) > 0 {
|
||||
if len(c.Source) > 0 {
|
||||
for i := range kdeploy.Spec.Template.PodSpec.Containers {
|
||||
kdeploy.Spec.Template.PodSpec.Containers[i].Image = s.Source
|
||||
kdeploy.Spec.Template.PodSpec.Containers[i].Image = c.Source
|
||||
kdeploy.Spec.Template.PodSpec.Containers[i].Command = []string{}
|
||||
kdeploy.Spec.Template.PodSpec.Containers[i].Args = []string{name}
|
||||
}
|
||||
|
Reference in New Issue
Block a user