-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use api types in status and core pkg (#719)
- Loading branch information
Showing
93 changed files
with
737 additions
and
902 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package v1 | ||
|
||
import "encoding/json" | ||
|
||
func (r *Resource) ResourceKey() string { | ||
return r.ID | ||
} | ||
|
||
// DeepCopy return a copy of resource | ||
func (r *Resource) DeepCopy() *Resource { | ||
var out Resource | ||
data, err := json.Marshal(r) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_ = json.Unmarshal(data, &out) | ||
return &out | ||
} | ||
|
||
func (rs Resources) Index() map[string]*Resource { | ||
m := make(map[string]*Resource) | ||
for i := range rs { | ||
m[rs[i].ResourceKey()] = &rs[i] | ||
} | ||
return m | ||
} | ||
|
||
// GVKIndex returns a map of GVK to resources, for now, only Kubernetes resources. | ||
func (rs Resources) GVKIndex() map[string][]*Resource { | ||
m := make(map[string][]*Resource) | ||
for i := range rs { | ||
resource := &rs[i] | ||
if resource.Type != Kubernetes { | ||
continue | ||
} | ||
gvk := resource.Extensions[ResourceExtensionGVK].(string) | ||
m[gvk] = append(m[gvk], resource) | ||
} | ||
return m | ||
} | ||
|
||
func (rs Resources) Len() int { return len(rs) } | ||
func (rs Resources) Swap(i, j int) { rs[i], rs[j] = rs[j], rs[i] } | ||
func (rs Resources) Less(i, j int) bool { | ||
switch { | ||
case rs[i].ID != rs[j].ID: | ||
return rs[i].ID < rs[j].ID | ||
default: | ||
return false | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 +1,3 @@ | ||
package internal | ||
package status | ||
|
||
const Group = "internal.kusionstack.io" |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
Oops, something went wrong.