Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteRootSyncSet: use specified OCI image #2722

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,26 @@ type RemoteRootSyncSet struct {
Status RemoteRootSyncSetStatus `json:"status,omitempty"`
}

func (o *RemoteRootSyncSet) GetSpec() *RemoteRootSyncSetSpec {
if o == nil {
return nil
}
return &o.Spec
}

// RemoteRootSyncSetSpec defines the desired state of RemoteRootSync
type RemoteRootSyncSetSpec struct {
ClusterRefs []*ClusterRef `json:"clusterRefs,omitempty"`
Template *RootSyncTemplate `json:"template,omitempty"`
}

func (o *RemoteRootSyncSetSpec) GetTemplate() *RootSyncTemplate {
if o == nil {
return nil
}
return o.Template
}

type ClusterRef struct {
ApiVersion string `json:"apiVersion,omitempty"`
Kind string `json:"kind,omitempty"`
Expand All @@ -61,10 +75,24 @@ type RootSyncTemplate struct {
OCI *OCISpec `json:"oci,omitempty"`
}

func (o *RootSyncTemplate) GetOCI() *OCISpec {
if o == nil {
return nil
}
return o.OCI
}

type OCISpec struct {
Repository string `json:"repository,omitempty"`
}

func (o *OCISpec) GetRepository() string {
if o == nil {
return ""
}
return o.Repository
}

// RootSyncSetStatus defines the observed state of RootSyncSet
type RemoteRootSyncSetStatus struct {
Targets []TargetStatus `json:"targets,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,17 @@ func (r *RemoteRootSyncSetReconciler) applyToClusterRef(ctx context.Context, sub

// BuildObjectsToApply config root sync
func (r *RemoteRootSyncSetReconciler) BuildObjectsToApply(ctx context.Context, subject *api.RemoteRootSyncSet) ([]*unstructured.Unstructured, error) {
// TODO: stop hard-coding the image source; get from a deployment instead
gcpProjectID := os.Getenv("GCP_PROJECT_ID")
imageName := oci.ImageTagName{
Image: "us-west1-docker.pkg.dev/" + gcpProjectID + "/deployment/myfirstnginx",
Tag: "v1",
repository := subject.GetSpec().GetTemplate().GetOCI().GetRepository()
if repository == "" {
return nil, fmt.Errorf("spec.template.oci.repository is not set")
}
imageName, err := oci.ParseImageTagName(repository)
if err != nil {
return nil, fmt.Errorf("unable to parse image %q: %w", repository, err)
}
klog.Infof("image name %s -> %#v", repository, *imageName)

digest, err := r.ociStorage.LookupImageTag(ctx, imageName)
digest, err := r.ociStorage.LookupImageTag(ctx, *imageName)
if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions porch/repository/pkg/oci/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func (i ImageTagName) ociReference() (name.Reference, error) {
return imageRef, nil
}

func ParseImageTagName(s string) (*ImageTagName, error) {
t, err := name.NewTag(s)
if err != nil {
return nil, fmt.Errorf("cannot parse %q as tag: %w", s, err)
}
return &ImageTagName{
Image: t.Repository.Name(),
Tag: t.TagStr(),
}, nil
}

// ImageDigestName holds an image we know by digest (which is immutable and more cacheable)
type ImageDigestName struct {
Image string
Expand Down