Skip to content

Commit

Permalink
Merge pull request #274 from briandowns/issue-269
Browse files Browse the repository at this point in the history
Update Directory Manifest Directory Exists Logic and Network Policy Existence Checks
  • Loading branch information
briandowns authored Aug 31, 2020
2 parents ead88dd + da3d543 commit a04621d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
19 changes: 12 additions & 7 deletions pkg/bootstrap/stage.go → pkg/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import (
"regexp"
"strings"

errors2 "github.com/pkg/errors"
"github.com/rancher/wrangler/pkg/merr"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
errors2 "github.com/pkg/errors"
"github.com/rancher/rke2/pkg/images"
"github.com/rancher/wrangler/pkg/merr"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -161,23 +160,29 @@ func extractFromDir(dir, prefix string, img v1.Image, imgName string) error {
return err
}
defer os.RemoveAll(tempDir)

r := mutate.Extract(img)
defer r.Close()

// extracting manifests
if err := extract(imgName, tempDir, prefix, r); err != nil {
return err
}
if err := os.Rename(tempDir, dir); err != nil && err != os.ErrExist {
return err
} else if err == nil {

// we're ignoring any returned errors since the likelihood is that
// the error is that the new path already exists. That's indicative of a
// previously bootstrapped system. If it's a different error, it's indicative
// of an operating system or filesystem issue.
if err := os.Rename(tempDir, dir); err == nil {
return nil
}
//manifests dir exists:

// manifests dir exists
files, err := ioutil.ReadDir(tempDir)
if err != nil {
return err
}

var errs []error
for _, file := range files {
src := filepath.Join(tempDir, file.Name())
Expand Down
15 changes: 8 additions & 7 deletions pkg/rke2/np.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ func setNetworkPolicy(ctx context.Context, namespace string, cs *kubernetes.Clie
ns.Annotations = make(map[string]string)
}
if _, ok := ns.Annotations[namespaceAnnotationNetworkPolicy]; !ok {
if _, err := cs.NetworkingV1().NetworkPolicies(namespace).Get(ctx, defaultNetworkPolicyName, metav1.GetOptions{}); err != nil {
if !apierrors.IsNotFound(err) {
return err
if _, err := cs.NetworkingV1().NetworkPolicies(namespace).Get(ctx, defaultNetworkPolicyName, metav1.GetOptions{}); err == nil {
if err := cs.NetworkingV1().NetworkPolicies(namespace).Delete(ctx, defaultNetworkPolicyName, metav1.DeleteOptions{}); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
}
}
if err := cs.NetworkingV1().NetworkPolicies(namespace).Delete(ctx, defaultNetworkPolicyName, metav1.DeleteOptions{}); err != nil {
return err
}
if _, err := cs.NetworkingV1().NetworkPolicies(namespace).Create(ctx, &networkPolicy, metav1.CreateOptions{}); err != nil {
return err
if !apierrors.IsAlreadyExists(err) {
return err
}
}
ns.Annotations[namespaceAnnotationNetworkPolicy] = cisAnnotationValue

Expand Down
2 changes: 1 addition & 1 deletion scripts/validate
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -ex

if [ -n "${SKIP_VALIDATE}" ]; then
if [ -n ${SKIP_VALIDATE} ]; then
echo "skipping validation. continuing..."
exit 0
fi
Expand Down

0 comments on commit a04621d

Please sign in to comment.